Merge branch 'benaadams/bens-magic-number' into dev
This commit is contained in:
commit
2016578f4e
|
|
@ -30,3 +30,5 @@ runtimes/
|
||||||
.build/
|
.build/
|
||||||
.testPublish/
|
.testPublish/
|
||||||
launchSettings.json
|
launchSettings.json
|
||||||
|
BenchmarkDotNet.Artifacts/
|
||||||
|
BDN.Generated/
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2AC
|
||||||
test\shared\DummyApplication.cs = test\shared\DummyApplication.cs
|
test\shared\DummyApplication.cs = test\shared\DummyApplication.cs
|
||||||
test\shared\HttpClientSlim.cs = test\shared\HttpClientSlim.cs
|
test\shared\HttpClientSlim.cs = test\shared\HttpClientSlim.cs
|
||||||
test\shared\LifetimeNotImplemented.cs = test\shared\LifetimeNotImplemented.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\MockSystemClock.cs = test\shared\MockSystemClock.cs
|
||||||
|
test\shared\SocketInputExtensions.cs = test\shared\SocketInputExtensions.cs
|
||||||
test\shared\TestApplicationErrorLogger.cs = test\shared\TestApplicationErrorLogger.cs
|
test\shared\TestApplicationErrorLogger.cs = test\shared\TestApplicationErrorLogger.cs
|
||||||
test\shared\TestConnection.cs = test\shared\TestConnection.cs
|
test\shared\TestConnection.cs = test\shared\TestConnection.cs
|
||||||
test\shared\TestKestrelTrace.cs = test\shared\TestKestrelTrace.cs
|
test\shared\TestKestrelTrace.cs = test\shared\TestKestrelTrace.cs
|
||||||
|
|
@ -45,6 +48,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{0EF2AC
|
||||||
test\shared\TestServiceContext.cs = test\shared\TestServiceContext.cs
|
test\shared\TestServiceContext.cs = test\shared\TestServiceContext.cs
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
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}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
|
@ -79,6 +84,10 @@ Global
|
||||||
{9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Debug|Any CPU.Build.0 = 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.ActiveCfg = Release|Any CPU
|
||||||
{9559A5F1-080C-4909-B6CF-7E4B3DC55748}.Release|Any CPU.Build.0 = 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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
@ -92,5 +101,6 @@ Global
|
||||||
{5F64B3C3-0C2E-431A-B820-A81BBFC863DA} = {2D5D5227-4DBD-499A-96B1-76A36B03B750}
|
{5F64B3C3-0C2E-431A-B820-A81BBFC863DA} = {2D5D5227-4DBD-499A-96B1-76A36B03B750}
|
||||||
{9559A5F1-080C-4909-B6CF-7E4B3DC55748} = {D3273454-EA07-41D2-BF0B-FCC3675C2483}
|
{9559A5F1-080C-4909-B6CF-7E4B3DC55748} = {D3273454-EA07-41D2-BF0B-FCC3675C2483}
|
||||||
{0EF2ACDF-012F-4472-A13A-4272419E2903} = {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}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Numerics;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
@ -24,6 +23,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
||||||
{
|
{
|
||||||
public abstract partial class Frame : IFrameControl
|
public abstract partial class Frame : IFrameControl
|
||||||
{
|
{
|
||||||
|
// 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<byte> _endChunkedResponseBytes = CreateAsciiByteArraySegment("0\r\n\r\n");
|
private static readonly ArraySegment<byte> _endChunkedResponseBytes = CreateAsciiByteArraySegment("0\r\n\r\n");
|
||||||
private static readonly ArraySegment<byte> _continueBytes = CreateAsciiByteArraySegment("HTTP/1.1 100 Continue\r\n\r\n");
|
private static readonly ArraySegment<byte> _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[] _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: Kestrel");
|
||||||
|
|
||||||
private static Vector<byte> _vectorCRs = new Vector<byte>((byte)'\r');
|
|
||||||
private static Vector<byte> _vectorLFs = new Vector<byte>((byte)'\n');
|
|
||||||
private static Vector<byte> _vectorColons = new Vector<byte>((byte)':');
|
|
||||||
private static Vector<byte> _vectorSpaces = new Vector<byte>((byte)' ');
|
|
||||||
private static Vector<byte> _vectorTabs = new Vector<byte>((byte)'\t');
|
|
||||||
private static Vector<byte> _vectorQuestionMarks = new Vector<byte>((byte)'?');
|
|
||||||
private static Vector<byte> _vectorPercentages = new Vector<byte>((byte)'%');
|
|
||||||
|
|
||||||
private readonly object _onStartingSync = new Object();
|
private readonly object _onStartingSync = new Object();
|
||||||
private readonly object _onCompletedSync = new Object();
|
private readonly object _onCompletedSync = new Object();
|
||||||
|
|
||||||
|
|
@ -952,7 +952,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
||||||
_requestProcessingStatus = RequestProcessingStatus.RequestStarted;
|
_requestProcessingStatus = RequestProcessingStatus.RequestStarted;
|
||||||
|
|
||||||
int bytesScanned;
|
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)
|
if (bytesScanned >= ServerOptions.Limits.MaxRequestLineSize)
|
||||||
{
|
{
|
||||||
|
|
@ -969,13 +969,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
||||||
var begin = scan;
|
var begin = scan;
|
||||||
if (!begin.GetKnownMethod(out method))
|
if (!begin.GetKnownMethod(out method))
|
||||||
{
|
{
|
||||||
if (scan.Seek(ref _vectorSpaces, ref end) == -1)
|
if (scan.Seek(ByteSpace, ref end) == -1)
|
||||||
{
|
{
|
||||||
RejectRequest(RequestRejectionReason.InvalidRequestLine,
|
RejectRequest(RequestRejectionReason.InvalidRequestLine,
|
||||||
Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty);
|
Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
method = begin.GetAsciiString(scan);
|
method = begin.GetAsciiString(ref scan);
|
||||||
|
|
||||||
if (method == null)
|
if (method == null)
|
||||||
{
|
{
|
||||||
|
|
@ -1002,16 +1002,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
||||||
scan.Take();
|
scan.Take();
|
||||||
begin = scan;
|
begin = scan;
|
||||||
var needDecode = false;
|
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)
|
if (chFound == -1)
|
||||||
{
|
{
|
||||||
RejectRequest(RequestRejectionReason.InvalidRequestLine,
|
RejectRequest(RequestRejectionReason.InvalidRequestLine,
|
||||||
Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty);
|
Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty);
|
||||||
}
|
}
|
||||||
else if (chFound == '%')
|
else if (chFound == BytePercentage)
|
||||||
{
|
{
|
||||||
needDecode = true;
|
needDecode = true;
|
||||||
chFound = scan.Seek(ref _vectorSpaces, ref _vectorQuestionMarks, ref end);
|
chFound = scan.Seek(ByteSpace, ByteQuestionMark, ref end);
|
||||||
if (chFound == -1)
|
if (chFound == -1)
|
||||||
{
|
{
|
||||||
RejectRequest(RequestRejectionReason.InvalidRequestLine,
|
RejectRequest(RequestRejectionReason.InvalidRequestLine,
|
||||||
|
|
@ -1023,20 +1023,20 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
||||||
var pathEnd = scan;
|
var pathEnd = scan;
|
||||||
|
|
||||||
var queryString = "";
|
var queryString = "";
|
||||||
if (chFound == '?')
|
if (chFound == ByteQuestionMark)
|
||||||
{
|
{
|
||||||
begin = scan;
|
begin = scan;
|
||||||
if (scan.Seek(ref _vectorSpaces, ref end) == -1)
|
if (scan.Seek(ByteSpace, ref end) == -1)
|
||||||
{
|
{
|
||||||
RejectRequest(RequestRejectionReason.InvalidRequestLine,
|
RejectRequest(RequestRejectionReason.InvalidRequestLine,
|
||||||
Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty);
|
Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty);
|
||||||
}
|
}
|
||||||
queryString = begin.GetAsciiString(scan);
|
queryString = begin.GetAsciiString(ref scan);
|
||||||
}
|
}
|
||||||
|
|
||||||
var queryEnd = scan;
|
var queryEnd = scan;
|
||||||
|
|
||||||
if (pathBegin.Peek() == ' ')
|
if (pathBegin.Peek() == ByteSpace)
|
||||||
{
|
{
|
||||||
RejectRequest(RequestRejectionReason.InvalidRequestLine,
|
RejectRequest(RequestRejectionReason.InvalidRequestLine,
|
||||||
Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty);
|
Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty);
|
||||||
|
|
@ -1044,7 +1044,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
||||||
|
|
||||||
scan.Take();
|
scan.Take();
|
||||||
begin = scan;
|
begin = scan;
|
||||||
if (scan.Seek(ref _vectorCRs, ref end) == -1)
|
if (scan.Seek(ByteCR, ref end) == -1)
|
||||||
{
|
{
|
||||||
RejectRequest(RequestRejectionReason.InvalidRequestLine,
|
RejectRequest(RequestRejectionReason.InvalidRequestLine,
|
||||||
Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty);
|
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
|
scan.Take(); // consume CR
|
||||||
if (scan.Take() != '\n')
|
if (scan.Take() != ByteLF)
|
||||||
{
|
{
|
||||||
RejectRequest(RequestRejectionReason.InvalidRequestLine,
|
RejectRequest(RequestRejectionReason.InvalidRequestLine,
|
||||||
Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty);
|
Log.IsEnabled(LogLevel.Information) ? start.GetAsciiStringEscaped(end, MaxInvalidRequestLineChars) : string.Empty);
|
||||||
|
|
@ -1081,16 +1081,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
||||||
if (needDecode)
|
if (needDecode)
|
||||||
{
|
{
|
||||||
// Read raw target before mutating memory.
|
// Read raw target before mutating memory.
|
||||||
rawTarget = pathBegin.GetAsciiString(queryEnd);
|
rawTarget = pathBegin.GetAsciiString(ref queryEnd);
|
||||||
|
|
||||||
// URI was encoded, unescape and then parse as utf8
|
// URI was encoded, unescape and then parse as utf8
|
||||||
pathEnd = UrlPathDecoder.Unescape(pathBegin, pathEnd);
|
pathEnd = UrlPathDecoder.Unescape(pathBegin, pathEnd);
|
||||||
requestUrlPath = pathBegin.GetUtf8String(pathEnd);
|
requestUrlPath = pathBegin.GetUtf8String(ref pathEnd);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// URI wasn't encoded, parse as ASCII
|
// URI wasn't encoded, parse as ASCII
|
||||||
requestUrlPath = pathBegin.GetAsciiString(pathEnd);
|
requestUrlPath = pathBegin.GetAsciiString(ref pathEnd);
|
||||||
|
|
||||||
if (queryString.Length == 0)
|
if (queryString.Length == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -1100,7 +1100,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rawTarget = pathBegin.GetAsciiString(queryEnd);
|
rawTarget = pathBegin.GetAsciiString(ref queryEnd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1208,7 +1208,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (ch == '\r')
|
else if (ch == ByteCR)
|
||||||
{
|
{
|
||||||
// Check for final CRLF.
|
// Check for final CRLF.
|
||||||
end.Take();
|
end.Take();
|
||||||
|
|
@ -1218,7 +1218,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (ch == '\n')
|
else if (ch == ByteLF)
|
||||||
{
|
{
|
||||||
ConnectionControl.CancelTimeout();
|
ConnectionControl.CancelTimeout();
|
||||||
consumed = end;
|
consumed = end;
|
||||||
|
|
@ -1228,7 +1228,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
||||||
// Headers don't end in CRLF line.
|
// Headers don't end in CRLF line.
|
||||||
RejectRequest(RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence);
|
RejectRequest(RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence);
|
||||||
}
|
}
|
||||||
else if (ch == ' ' || ch == '\t')
|
else if (ch == ByteSpace || ch == ByteTab)
|
||||||
{
|
{
|
||||||
RejectRequest(RequestRejectionReason.HeaderLineMustNotStartWithWhitespace);
|
RejectRequest(RequestRejectionReason.HeaderLineMustNotStartWithWhitespace);
|
||||||
}
|
}
|
||||||
|
|
@ -1241,7 +1241,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
||||||
}
|
}
|
||||||
|
|
||||||
int bytesScanned;
|
int bytesScanned;
|
||||||
if (end.Seek(ref _vectorLFs, out bytesScanned, _remainingRequestHeadersBytesAllowed) == -1)
|
if (end.Seek(ByteLF, out bytesScanned, _remainingRequestHeadersBytesAllowed) == -1)
|
||||||
{
|
{
|
||||||
if (bytesScanned >= _remainingRequestHeadersBytesAllowed)
|
if (bytesScanned >= _remainingRequestHeadersBytesAllowed)
|
||||||
{
|
{
|
||||||
|
|
@ -1254,7 +1254,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
||||||
}
|
}
|
||||||
|
|
||||||
var beginName = scan;
|
var beginName = scan;
|
||||||
if (scan.Seek(ref _vectorColons, ref end) == -1)
|
if (scan.Seek(ByteColon, ref end) == -1)
|
||||||
{
|
{
|
||||||
RejectRequest(RequestRejectionReason.NoColonCharacterFoundInHeaderLine);
|
RejectRequest(RequestRejectionReason.NoColonCharacterFoundInHeaderLine);
|
||||||
}
|
}
|
||||||
|
|
@ -1263,7 +1263,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
||||||
scan.Take();
|
scan.Take();
|
||||||
|
|
||||||
var validateName = beginName;
|
var validateName = beginName;
|
||||||
if (validateName.Seek(ref _vectorSpaces, ref _vectorTabs, ref endName) != -1)
|
if (validateName.Seek(ByteSpace, ByteTab, ref endName) != -1)
|
||||||
{
|
{
|
||||||
RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName);
|
RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName);
|
||||||
}
|
}
|
||||||
|
|
@ -1271,14 +1271,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
||||||
var beginValue = scan;
|
var beginValue = scan;
|
||||||
ch = scan.Take();
|
ch = scan.Take();
|
||||||
|
|
||||||
while (ch == ' ' || ch == '\t')
|
while (ch == ByteSpace || ch == ByteTab)
|
||||||
{
|
{
|
||||||
beginValue = scan;
|
beginValue = scan;
|
||||||
ch = scan.Take();
|
ch = scan.Take();
|
||||||
}
|
}
|
||||||
|
|
||||||
scan = beginValue;
|
scan = beginValue;
|
||||||
if (scan.Seek(ref _vectorCRs, ref end) == -1)
|
if (scan.Seek(ByteCR, ref end) == -1)
|
||||||
{
|
{
|
||||||
RejectRequest(RequestRejectionReason.MissingCRInHeaderLine);
|
RejectRequest(RequestRejectionReason.MissingCRInHeaderLine);
|
||||||
}
|
}
|
||||||
|
|
@ -1287,7 +1287,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
||||||
ch = scan.Take(); // expecting '\n'
|
ch = scan.Take(); // expecting '\n'
|
||||||
end = scan;
|
end = scan;
|
||||||
|
|
||||||
if (ch != '\n')
|
if (ch != ByteLF)
|
||||||
{
|
{
|
||||||
RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR);
|
RejectRequest(RequestRejectionReason.HeaderValueMustNotContainCR);
|
||||||
}
|
}
|
||||||
|
|
@ -1297,7 +1297,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (next == ' ' || next == '\t')
|
else if (next == ByteSpace || next == ByteTab)
|
||||||
{
|
{
|
||||||
// From https://tools.ietf.org/html/rfc7230#section-3.2.4:
|
// From https://tools.ietf.org/html/rfc7230#section-3.2.4:
|
||||||
//
|
//
|
||||||
|
|
@ -1330,18 +1330,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
||||||
var endValue = scan;
|
var endValue = scan;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
ws.Seek(ref _vectorSpaces, ref _vectorTabs, ref _vectorCRs);
|
ws.Seek(ByteSpace, ByteTab, ByteCR);
|
||||||
endValue = ws;
|
endValue = ws;
|
||||||
|
|
||||||
ch = ws.Take();
|
ch = ws.Take();
|
||||||
while (ch == ' ' || ch == '\t')
|
while (ch == ByteSpace || ch == ByteTab)
|
||||||
{
|
{
|
||||||
ch = ws.Take();
|
ch = ws.Take();
|
||||||
}
|
}
|
||||||
} while (ch != '\r');
|
} while (ch != ByteCR);
|
||||||
|
|
||||||
var name = beginName.GetArraySegment(endName);
|
var name = beginName.GetArraySegment(endName);
|
||||||
var value = beginValue.GetAsciiString(endValue);
|
var value = beginValue.GetAsciiString(ref endValue);
|
||||||
|
|
||||||
consumed = scan;
|
consumed = scan;
|
||||||
requestHeaders.Append(name.Array, name.Offset, name.Count, value);
|
requestHeaders.Append(name.Array, name.Offset, name.Count, value);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Numerics;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
@ -390,9 +389,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private class ForChunkedEncoding : MessageBody
|
private class ForChunkedEncoding : MessageBody
|
||||||
{
|
{
|
||||||
// This causes an InvalidProgramException if made static
|
// byte consts don't have a data type annotation so we pre-cast it
|
||||||
// https://github.com/dotnet/corefx/issues/8825
|
private const byte ByteCR = (byte)'\r';
|
||||||
private Vector<byte> _vectorCRs = new Vector<byte>((byte)'\r');
|
|
||||||
|
|
||||||
private readonly SocketInput _input;
|
private readonly SocketInput _input;
|
||||||
private readonly FrameRequestHeaders _requestHeaders;
|
private readonly FrameRequestHeaders _requestHeaders;
|
||||||
|
|
@ -613,7 +611,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
||||||
// Just drain the data
|
// Just drain the data
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (scan.Seek(ref _vectorCRs) == -1)
|
if (scan.Seek(ByteCR) == -1)
|
||||||
{
|
{
|
||||||
// End marker not found yet
|
// End marker not found yet
|
||||||
consumed = scan;
|
consumed = scan;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
|
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
|
||||||
{
|
{
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -3,16 +3,14 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
|
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
|
||||||
{
|
{
|
||||||
public static class MemoryPoolIteratorExtensions
|
public static class MemoryPoolIteratorExtensions
|
||||||
{
|
{
|
||||||
private static readonly Encoding _utf8 = Encoding.UTF8;
|
|
||||||
|
|
||||||
public const string Http10Version = "HTTP/1.0";
|
public const string Http10Version = "HTTP/1.0";
|
||||||
public const string Http11Version = "HTTP/1.1";
|
public const string Http11Version = "HTTP/1.1";
|
||||||
|
|
||||||
|
|
@ -71,62 +69,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)
|
public static string GetAsciiStringEscaped(this MemoryPoolIterator start, MemoryPoolIterator end, int maxChars)
|
||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
|
|
@ -147,102 +89,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
|
||||||
return sb.ToString();
|
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<byte> GetArraySegment(this MemoryPoolIterator start, MemoryPoolIterator end)
|
|
||||||
{
|
|
||||||
if (start.IsDefault || end.IsDefault)
|
|
||||||
{
|
|
||||||
return default(ArraySegment<byte>);
|
|
||||||
}
|
|
||||||
if (end.Block == start.Block)
|
|
||||||
{
|
|
||||||
return new ArraySegment<byte>(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<byte>(array, 0, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ArraySegment<byte> PeekArraySegment(this MemoryPoolIterator iter)
|
public static ArraySegment<byte> PeekArraySegment(this MemoryPoolIterator iter)
|
||||||
{
|
{
|
||||||
if (iter.IsDefault || iter.IsEnd)
|
if (iter.IsDefault || iter.IsEnd)
|
||||||
|
|
@ -283,6 +129,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
|
||||||
/// <param name="begin">The iterator from which to start the known string lookup.</param>
|
/// <param name="begin">The iterator from which to start the known string lookup.</param>
|
||||||
/// <param name="knownMethod">A reference to a pre-allocated known string, if the input matches any.</param>
|
/// <param name="knownMethod">A reference to a pre-allocated known string, if the input matches any.</param>
|
||||||
/// <returns><c>true</c> if the input matches a known string, <c>false</c> otherwise.</returns>
|
/// <returns><c>true</c> if the input matches a known string, <c>false</c> otherwise.</returns>
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static bool GetKnownMethod(this MemoryPoolIterator begin, out string knownMethod)
|
public static bool GetKnownMethod(this MemoryPoolIterator begin, out string knownMethod)
|
||||||
{
|
{
|
||||||
knownMethod = null;
|
knownMethod = null;
|
||||||
|
|
@ -323,6 +170,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
|
||||||
/// <param name="begin">The iterator from which to start the known string lookup.</param>
|
/// <param name="begin">The iterator from which to start the known string lookup.</param>
|
||||||
/// <param name="knownVersion">A reference to a pre-allocated known string, if the input matches any.</param>
|
/// <param name="knownVersion">A reference to a pre-allocated known string, if the input matches any.</param>
|
||||||
/// <returns><c>true</c> if the input matches a known string, <c>false</c> otherwise.</returns>
|
/// <returns><c>true</c> if the input matches a known string, <c>false</c> otherwise.</returns>
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static bool GetKnownVersion(this MemoryPoolIterator begin, out string knownVersion)
|
public static bool GetKnownVersion(this MemoryPoolIterator begin, out string knownVersion)
|
||||||
{
|
{
|
||||||
knownVersion = null;
|
knownVersion = null;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.FunctionalTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
||||||
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.KestrelTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.KestrelTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
||||||
|
[assembly: InternalsVisibleTo("Microsoft.AspNetCore.Server.Kestrel.Performance, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
||||||
[assembly: AssemblyMetadata("Serviceable", "True")]
|
[assembly: AssemblyMetadata("Serviceable", "True")]
|
||||||
[assembly: NeutralResourcesLanguage("en-us")]
|
[assembly: NeutralResourcesLanguage("en-us")]
|
||||||
[assembly: AssemblyCompany("Microsoft Corporation.")]
|
[assembly: AssemblyCompany("Microsoft Corporation.")]
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||||
|
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<ProjectGuid>70567566-524c-4b67-9b59-e5c206d6c2eb</ProjectGuid>
|
||||||
|
<RootNamespace>Microsoft.AspNetCore.Server.Kestrel.Performance</RootNamespace>
|
||||||
|
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
|
||||||
|
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
|
||||||
|
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<DnxInvisibleFolder Include="BenchmarkDotNet.Artifacts\" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||||
|
</Project>
|
||||||
|
|
@ -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 BenchmarkDotNet.Environments;
|
||||||
|
using BenchmarkDotNet.Jobs;
|
||||||
|
using BenchmarkDotNet.Properties;
|
||||||
|
using BenchmarkDotNet.Running;
|
||||||
|
using BenchmarkDotNet.Toolchains;
|
||||||
|
|
||||||
|
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<RequestParsing>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Flags]
|
||||||
|
public enum BenchmarkType : uint
|
||||||
|
{
|
||||||
|
RequestParsing = 1,
|
||||||
|
// add new ones in powers of two - e.g. 2,4,8,16...
|
||||||
|
|
||||||
|
All = uint.MaxValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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 RequestParsing
|
||||||
|
```
|
||||||
|
To run all use `All` as parameter
|
||||||
|
```
|
||||||
|
dotnet run All
|
||||||
|
```
|
||||||
|
Using no parameter will list all available benchmarks
|
||||||
|
|
@ -0,0 +1,188 @@
|
||||||
|
// Copyright (c) .NET Foundation. All 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 Microsoft.AspNetCore.Testing;
|
||||||
|
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<object> 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 TestKestrelTrace());
|
||||||
|
ThreadPool = new LoggingThreadPool(Trace);
|
||||||
|
MemoryPool = new MemoryPool();
|
||||||
|
SocketInput = new SocketInput(MemoryPool, ThreadPool);
|
||||||
|
|
||||||
|
var connectionContext = new MockConnection(new KestrelServerOptions());
|
||||||
|
connectionContext.SocketInput = SocketInput;
|
||||||
|
|
||||||
|
Frame = new Frame<object>(application: null, context: connectionContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Cleanup]
|
||||||
|
public void Cleanup()
|
||||||
|
{
|
||||||
|
SocketInput.IncomingFin();
|
||||||
|
SocketInput.Dispose();
|
||||||
|
MemoryPool.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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 BenchmarkDotNet.Configs;
|
||||||
|
using BenchmarkDotNet.Engines;
|
||||||
|
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(BenchmarkDotNet.Environments.Runtime.Core).
|
||||||
|
WithRemoveOutliers(false).
|
||||||
|
With(new GcMode() { Server = true }).
|
||||||
|
With(RunStrategy.Throughput).
|
||||||
|
WithLaunchCount(3).
|
||||||
|
WithWarmupCount(5).
|
||||||
|
WithTargetCount(10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"projects": [ "..\\" ]
|
||||||
|
}
|
||||||
|
|
@ -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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
var begin = mem.GetIterator();
|
var begin = mem.GetIterator();
|
||||||
var end = GetIterator(begin, byteRange.Length);
|
var end = GetIterator(begin, byteRange.Length);
|
||||||
|
|
||||||
var s = begin.GetAsciiString(end);
|
var s = begin.GetAsciiString(ref end);
|
||||||
|
|
||||||
Assert.Equal(s.Length, byteRange.Length);
|
Assert.Equal(s.Length, byteRange.Length);
|
||||||
|
|
||||||
|
|
@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
var begin = mem.GetIterator();
|
var begin = mem.GetIterator();
|
||||||
var end = GetIterator(begin, byteRange.Length);
|
var end = GetIterator(begin, byteRange.Length);
|
||||||
|
|
||||||
Assert.Throws<BadHttpRequestException>(() => begin.GetAsciiString(end));
|
Assert.Throws<BadHttpRequestException>(() => begin.GetAsciiString(ref end));
|
||||||
|
|
||||||
pool.Return(mem);
|
pool.Return(mem);
|
||||||
}
|
}
|
||||||
|
|
@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
var begin = mem0.GetIterator();
|
var begin = mem0.GetIterator();
|
||||||
var end = GetIterator(begin, expectedByteRange.Length);
|
var end = GetIterator(begin, expectedByteRange.Length);
|
||||||
|
|
||||||
var s = begin.GetAsciiString(end);
|
var s = begin.GetAsciiString(ref end);
|
||||||
|
|
||||||
Assert.Equal(s.Length, expectedByteRange.Length);
|
Assert.Equal(s.Length, expectedByteRange.Length);
|
||||||
|
|
||||||
|
|
@ -135,7 +135,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
var begin = mem0.GetIterator();
|
var begin = mem0.GetIterator();
|
||||||
var end = GetIterator(begin, expectedByteRange.Length);
|
var end = GetIterator(begin, expectedByteRange.Length);
|
||||||
|
|
||||||
var s = begin.GetAsciiString(end);
|
var s = begin.GetAsciiString(ref end);
|
||||||
|
|
||||||
Assert.Equal(expectedByteRange.Length, s.Length);
|
Assert.Equal(expectedByteRange.Length, s.Length);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,35 +19,31 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
block.Array[block.End++] = ch;
|
block.Array[block.End++] = ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
var vectorMaxValues = new Vector<byte>(byte.MaxValue);
|
|
||||||
|
|
||||||
var iterator = block.GetIterator();
|
var iterator = block.GetIterator();
|
||||||
foreach (var ch in Enumerable.Range(0, 256).Select(x => (byte)x))
|
foreach (var ch in Enumerable.Range(0, 256).Select(x => (byte)x))
|
||||||
{
|
{
|
||||||
var vectorCh = new Vector<byte>(ch);
|
|
||||||
|
|
||||||
var hit = iterator;
|
var hit = iterator;
|
||||||
hit.Seek(ref vectorCh);
|
hit.Seek(ch);
|
||||||
Assert.Equal(ch, iterator.GetLength(hit));
|
Assert.Equal(ch, iterator.GetLength(hit));
|
||||||
|
|
||||||
hit = iterator;
|
hit = iterator;
|
||||||
hit.Seek(ref vectorCh, ref vectorMaxValues);
|
hit.Seek(ch, byte.MaxValue);
|
||||||
Assert.Equal(ch, iterator.GetLength(hit));
|
Assert.Equal(ch, iterator.GetLength(hit));
|
||||||
|
|
||||||
hit = iterator;
|
hit = iterator;
|
||||||
hit.Seek(ref vectorMaxValues, ref vectorCh);
|
hit.Seek(byte.MaxValue, ch);
|
||||||
Assert.Equal(ch, iterator.GetLength(hit));
|
Assert.Equal(ch, iterator.GetLength(hit));
|
||||||
|
|
||||||
hit = iterator;
|
hit = iterator;
|
||||||
hit.Seek(ref vectorCh, ref vectorMaxValues, ref vectorMaxValues);
|
hit.Seek(ch, byte.MaxValue, byte.MaxValue);
|
||||||
Assert.Equal(ch, iterator.GetLength(hit));
|
Assert.Equal(ch, iterator.GetLength(hit));
|
||||||
|
|
||||||
hit = iterator;
|
hit = iterator;
|
||||||
hit.Seek(ref vectorMaxValues, ref vectorCh, ref vectorMaxValues);
|
hit.Seek(byte.MaxValue, ch, byte.MaxValue);
|
||||||
Assert.Equal(ch, iterator.GetLength(hit));
|
Assert.Equal(ch, iterator.GetLength(hit));
|
||||||
|
|
||||||
hit = iterator;
|
hit = iterator;
|
||||||
hit.Seek(ref vectorCh, ref vectorMaxValues, ref vectorMaxValues);
|
hit.Seek(ch, byte.MaxValue, byte.MaxValue);
|
||||||
Assert.Equal(ch, iterator.GetLength(hit));
|
Assert.Equal(ch, iterator.GetLength(hit));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,35 +73,31 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
block3.Array[block3.End++] = ch;
|
block3.Array[block3.End++] = ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
var vectorMaxValues = new Vector<byte>(byte.MaxValue);
|
|
||||||
|
|
||||||
var iterator = block1.GetIterator();
|
var iterator = block1.GetIterator();
|
||||||
foreach (var ch in Enumerable.Range(0, 256).Select(x => (byte)x))
|
foreach (var ch in Enumerable.Range(0, 256).Select(x => (byte)x))
|
||||||
{
|
{
|
||||||
var vectorCh = new Vector<byte>(ch);
|
|
||||||
|
|
||||||
var hit = iterator;
|
var hit = iterator;
|
||||||
hit.Seek(ref vectorCh);
|
hit.Seek(ch);
|
||||||
Assert.Equal(ch, iterator.GetLength(hit));
|
Assert.Equal(ch, iterator.GetLength(hit));
|
||||||
|
|
||||||
hit = iterator;
|
hit = iterator;
|
||||||
hit.Seek(ref vectorCh, ref vectorMaxValues);
|
hit.Seek(ch, byte.MaxValue);
|
||||||
Assert.Equal(ch, iterator.GetLength(hit));
|
Assert.Equal(ch, iterator.GetLength(hit));
|
||||||
|
|
||||||
hit = iterator;
|
hit = iterator;
|
||||||
hit.Seek(ref vectorMaxValues, ref vectorCh);
|
hit.Seek(byte.MaxValue, ch);
|
||||||
Assert.Equal(ch, iterator.GetLength(hit));
|
Assert.Equal(ch, iterator.GetLength(hit));
|
||||||
|
|
||||||
hit = iterator;
|
hit = iterator;
|
||||||
hit.Seek(ref vectorCh, ref vectorMaxValues, ref vectorMaxValues);
|
hit.Seek(ch, byte.MaxValue, byte.MaxValue);
|
||||||
Assert.Equal(ch, iterator.GetLength(hit));
|
Assert.Equal(ch, iterator.GetLength(hit));
|
||||||
|
|
||||||
hit = iterator;
|
hit = iterator;
|
||||||
hit.Seek(ref vectorMaxValues, ref vectorCh, ref vectorMaxValues);
|
hit.Seek(byte.MaxValue, ch, byte.MaxValue);
|
||||||
Assert.Equal(ch, iterator.GetLength(hit));
|
Assert.Equal(ch, iterator.GetLength(hit));
|
||||||
|
|
||||||
hit = iterator;
|
hit = iterator;
|
||||||
hit.Seek(ref vectorMaxValues, ref vectorMaxValues, ref vectorCh);
|
hit.Seek(byte.MaxValue, byte.MaxValue, ch);
|
||||||
Assert.Equal(ch, iterator.GetLength(hit));
|
Assert.Equal(ch, iterator.GetLength(hit));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
for (int i = 0; i < Vector<byte>.Count; i++)
|
for (int i = 0; i < Vector<byte>.Count; i++)
|
||||||
{
|
{
|
||||||
Vector<byte> vector = new Vector<byte>(bytes);
|
Vector<byte> vector = new Vector<byte>(bytes);
|
||||||
Assert.Equal(i, MemoryPoolIterator.FindFirstEqualByte(ref vector));
|
Assert.Equal(i, MemoryPoolIterator.LocateFirstFoundByte(vector));
|
||||||
bytes[i] = 0;
|
bytes[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,27 +40,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
{
|
{
|
||||||
bytes[i] = 1;
|
bytes[i] = 1;
|
||||||
Vector<byte> vector = new Vector<byte>(bytes);
|
Vector<byte> vector = new Vector<byte>(bytes);
|
||||||
Assert.Equal(i, MemoryPoolIterator.FindFirstEqualByte(ref vector));
|
Assert.Equal(i, MemoryPoolIterator.LocateFirstFoundByte(vector));
|
||||||
bytes[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public void TestFindFirstEqualByteSlow()
|
|
||||||
{
|
|
||||||
var bytes = Enumerable.Repeat<byte>(0xff, Vector<byte>.Count).ToArray();
|
|
||||||
for (int i = 0; i < Vector<byte>.Count; i++)
|
|
||||||
{
|
|
||||||
Vector<byte> vector = new Vector<byte>(bytes);
|
|
||||||
Assert.Equal(i, MemoryPoolIterator.FindFirstEqualByteSlow(ref vector));
|
|
||||||
bytes[i] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < Vector<byte>.Count; i++)
|
|
||||||
{
|
|
||||||
bytes[i] = 1;
|
|
||||||
Vector<byte> vector = new Vector<byte>(bytes);
|
|
||||||
Assert.Equal(i, MemoryPoolIterator.FindFirstEqualByteSlow(ref vector));
|
|
||||||
bytes[i] = 0;
|
bytes[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -98,21 +78,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
int found = -1;
|
int found = -1;
|
||||||
if (searchFor.Length == 1)
|
if (searchFor.Length == 1)
|
||||||
{
|
{
|
||||||
var search0 = new Vector<byte>((byte) searchFor[0]);
|
found = begin.Seek((byte)searchFor[0]);
|
||||||
found = begin.Seek(ref search0);
|
|
||||||
}
|
}
|
||||||
else if (searchFor.Length == 2)
|
else if (searchFor.Length == 2)
|
||||||
{
|
{
|
||||||
var search0 = new Vector<byte>((byte) searchFor[0]);
|
found = begin.Seek((byte)searchFor[0], (byte)searchFor[1]);
|
||||||
var search1 = new Vector<byte>((byte) searchFor[1]);
|
|
||||||
found = begin.Seek(ref search0, ref search1);
|
|
||||||
}
|
}
|
||||||
else if (searchFor.Length == 3)
|
else if (searchFor.Length == 3)
|
||||||
{
|
{
|
||||||
var search0 = new Vector<byte>((byte) searchFor[0]);
|
found = begin.Seek((byte)searchFor[0], (byte)searchFor[1], (byte)searchFor[2]);
|
||||||
var search1 = new Vector<byte>((byte) searchFor[1]);
|
|
||||||
var search2 = new Vector<byte>((byte) searchFor[2]);
|
|
||||||
found = begin.Seek(ref search0, ref search1, ref search2);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -180,7 +154,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can't put anything by the end
|
// Can't put anything by the end
|
||||||
Assert.False(head.Put(0xFF));
|
Assert.ThrowsAny<InvalidOperationException>(() => head.Put(0xFF));
|
||||||
|
|
||||||
for (var i = 0; i < 4; ++i)
|
for (var i = 0; i < 4; ++i)
|
||||||
{
|
{
|
||||||
|
|
@ -544,20 +518,25 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
public void SkipThrowsWhenSkippingMoreBytesThanAvailableInMultipleBlocks()
|
public void SkipThrowsWhenSkippingMoreBytesThanAvailableInMultipleBlocks()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var block = _pool.Lease();
|
var firstBlock = _pool.Lease();
|
||||||
block.End += 3;
|
firstBlock.End += 3;
|
||||||
|
|
||||||
var nextBlock = _pool.Lease();
|
var middleBlock = _pool.Lease();
|
||||||
nextBlock.End += 2;
|
middleBlock.End += 1;
|
||||||
block.Next = nextBlock;
|
firstBlock.Next = middleBlock;
|
||||||
|
|
||||||
var scan = block.GetIterator();
|
var finalBlock = _pool.Lease();
|
||||||
|
finalBlock.End += 2;
|
||||||
|
middleBlock.Next = finalBlock;
|
||||||
|
|
||||||
|
var scan = firstBlock.GetIterator();
|
||||||
|
|
||||||
// Act/Assert
|
// Act/Assert
|
||||||
Assert.ThrowsAny<InvalidOperationException>(() => scan.Skip(8));
|
Assert.ThrowsAny<InvalidOperationException>(() => scan.Skip(8));
|
||||||
|
|
||||||
_pool.Return(block);
|
_pool.Return(firstBlock);
|
||||||
_pool.Return(nextBlock);
|
_pool.Return(middleBlock);
|
||||||
|
_pool.Return(finalBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
@ -759,7 +738,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var seekVector = new Vector<byte>((byte)seek);
|
|
||||||
|
|
||||||
block = _pool.Lease();
|
block = _pool.Lease();
|
||||||
var chars = input.ToString().ToCharArray().Select(c => (byte)c).ToArray();
|
var chars = input.ToString().ToCharArray().Select(c => (byte)c).ToArray();
|
||||||
|
|
@ -769,7 +747,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
int bytesScanned;
|
int bytesScanned;
|
||||||
var returnValue = scan.Seek(ref seekVector, out bytesScanned, limit);
|
var returnValue = scan.Seek((byte)seek, out bytesScanned, limit);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(expectedBytesScanned, bytesScanned);
|
Assert.Equal(expectedBytesScanned, bytesScanned);
|
||||||
|
|
@ -799,8 +777,6 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var seekVector = new Vector<byte>((byte)seek);
|
|
||||||
|
|
||||||
var input1 = input.Substring(0, input.Length / 2);
|
var input1 = input.Substring(0, input.Length / 2);
|
||||||
block1 = _pool.Lease();
|
block1 = _pool.Lease();
|
||||||
var chars1 = input1.ToCharArray().Select(c => (byte)c).ToArray();
|
var chars1 = input1.ToCharArray().Select(c => (byte)c).ToArray();
|
||||||
|
|
@ -821,7 +797,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
int bytesScanned;
|
int bytesScanned;
|
||||||
var returnValue = scan.Seek(ref seekVector, out bytesScanned, limit);
|
var returnValue = scan.Seek((byte)seek, out bytesScanned, limit);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(expectedBytesScanned, bytesScanned);
|
Assert.Equal(expectedBytesScanned, bytesScanned);
|
||||||
|
|
@ -855,9 +831,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var seekVector = new Vector<byte>((byte)seek);
|
var afterSeek = (byte)'B';
|
||||||
var limitAtVector = new Vector<byte>((byte)limitAt);
|
|
||||||
var afterSeekVector = new Vector<byte>((byte)'B');
|
|
||||||
|
|
||||||
block = _pool.Lease();
|
block = _pool.Lease();
|
||||||
var chars = input.ToCharArray().Select(c => (byte)c).ToArray();
|
var chars = input.ToCharArray().Select(c => (byte)c).ToArray();
|
||||||
|
|
@ -872,13 +846,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
var end = scan1;
|
var end = scan1;
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var endReturnValue = end.Seek(ref limitAtVector);
|
var endReturnValue = end.Seek((byte)limitAt);
|
||||||
var returnValue1 = scan1.Seek(ref seekVector, ref end);
|
var returnValue1 = scan1.Seek((byte)seek, ref end);
|
||||||
var returnValue2_1 = scan2_1.Seek(ref seekVector, ref afterSeekVector, ref end);
|
var returnValue2_1 = scan2_1.Seek((byte)seek, afterSeek, ref end);
|
||||||
var returnValue2_2 = scan2_2.Seek(ref afterSeekVector, ref seekVector, ref end);
|
var returnValue2_2 = scan2_2.Seek(afterSeek, (byte)seek, ref end);
|
||||||
var returnValue3_1 = scan3_1.Seek(ref seekVector, ref afterSeekVector, ref afterSeekVector, ref end);
|
var returnValue3_1 = scan3_1.Seek((byte)seek, afterSeek, afterSeek, ref end);
|
||||||
var returnValue3_2 = scan3_2.Seek(ref afterSeekVector, ref seekVector, ref afterSeekVector, ref end);
|
var returnValue3_2 = scan3_2.Seek(afterSeek, (byte)seek, afterSeek, ref end);
|
||||||
var returnValue3_3 = scan3_3.Seek(ref afterSeekVector, ref afterSeekVector, ref seekVector, ref end);
|
var returnValue3_3 = scan3_3.Seek(afterSeek, afterSeek, (byte)seek, ref end);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(input.Contains(limitAt) ? limitAt : -1, endReturnValue);
|
Assert.Equal(input.Contains(limitAt) ? limitAt : -1, endReturnValue);
|
||||||
|
|
@ -922,9 +896,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var seekVector = new Vector<byte>((byte)seek);
|
var afterSeek = (byte)'B';
|
||||||
var limitAtVector = new Vector<byte>((byte)limitAt);
|
|
||||||
var afterSeekVector = new Vector<byte>((byte)'B');
|
|
||||||
|
|
||||||
var input1 = input.Substring(0, input.Length / 2);
|
var input1 = input.Substring(0, input.Length / 2);
|
||||||
block1 = _pool.Lease();
|
block1 = _pool.Lease();
|
||||||
|
|
@ -951,13 +923,13 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
var end = scan1;
|
var end = scan1;
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var endReturnValue = end.Seek(ref limitAtVector);
|
var endReturnValue = end.Seek((byte)limitAt);
|
||||||
var returnValue1 = scan1.Seek(ref seekVector, ref end);
|
var returnValue1 = scan1.Seek((byte)seek, ref end);
|
||||||
var returnValue2_1 = scan2_1.Seek(ref seekVector, ref afterSeekVector, ref end);
|
var returnValue2_1 = scan2_1.Seek((byte)seek, afterSeek, ref end);
|
||||||
var returnValue2_2 = scan2_2.Seek(ref afterSeekVector, ref seekVector, ref end);
|
var returnValue2_2 = scan2_2.Seek(afterSeek, (byte)seek, ref end);
|
||||||
var returnValue3_1 = scan3_1.Seek(ref seekVector, ref afterSeekVector, ref afterSeekVector, ref end);
|
var returnValue3_1 = scan3_1.Seek((byte)seek, afterSeek, afterSeek, ref end);
|
||||||
var returnValue3_2 = scan3_2.Seek(ref afterSeekVector, ref seekVector, ref afterSeekVector, ref end);
|
var returnValue3_2 = scan3_2.Seek(afterSeek, (byte)seek, afterSeek, ref end);
|
||||||
var returnValue3_3 = scan3_3.Seek(ref afterSeekVector, ref afterSeekVector, ref seekVector, ref end);
|
var returnValue3_3 = scan3_3.Seek(afterSeek, afterSeek, (byte)seek, ref end);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(input.Contains(limitAt) ? limitAt : -1, endReturnValue);
|
Assert.Equal(input.Contains(limitAt) ? limitAt : -1, endReturnValue);
|
||||||
|
|
@ -999,6 +971,216 @@ 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.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<byte>)));
|
||||||
|
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<byte>));
|
||||||
|
default(MemoryPoolIterator).CopyFromAscii("");
|
||||||
|
Assert.ThrowsAny<InvalidOperationException>(() => default(MemoryPoolIterator).Put(byteCr));
|
||||||
|
Assert.ThrowsAny<InvalidOperationException>(() => default(MemoryPoolIterator).GetLength(end));
|
||||||
|
Assert.ThrowsAny<InvalidOperationException>(() => 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]
|
[Theory]
|
||||||
[InlineData("a", "a", 1)]
|
[InlineData("a", "a", 1)]
|
||||||
[InlineData("ab", "a...", 1)]
|
[InlineData("ab", "a...", 1)]
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,11 @@ using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel;
|
using Microsoft.AspNetCore.Server.Kestrel;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
|
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
|
||||||
using Microsoft.AspNetCore.Server.KestrelTests.TestHelpers;
|
|
||||||
using Microsoft.Extensions.Internal;
|
using Microsoft.Extensions.Internal;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Sdk;
|
using Xunit.Sdk;
|
||||||
|
using Microsoft.AspNetCore.Testing;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.KestrelTests
|
namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -167,7 +167,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
var end = GetIterator(begin, rawLength);
|
var end = GetIterator(begin, rawLength);
|
||||||
|
|
||||||
var end2 = UrlPathDecoder.Unescape(begin, end);
|
var end2 = UrlPathDecoder.Unescape(begin, end);
|
||||||
var result = begin.GetUtf8String(end2);
|
var result = begin.GetUtf8String(ref end2);
|
||||||
|
|
||||||
Assert.Equal(expectLength, result.Length);
|
Assert.Equal(expectLength, result.Length);
|
||||||
Assert.Equal(expect, result);
|
Assert.Equal(expect, result);
|
||||||
|
|
@ -201,7 +201,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
var end = GetIterator(begin, raw.Length);
|
var end = GetIterator(begin, raw.Length);
|
||||||
|
|
||||||
var result = UrlPathDecoder.Unescape(begin, end);
|
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)
|
private void PositiveAssert(MemoryPoolBlock mem, string raw)
|
||||||
|
|
@ -210,7 +210,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
var end = GetIterator(begin, raw.Length);
|
var end = GetIterator(begin, raw.Length);
|
||||||
|
|
||||||
var result = UrlPathDecoder.Unescape(begin, end);
|
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)
|
private void NegativeAssert(MemoryPoolBlock mem, string raw)
|
||||||
|
|
@ -219,7 +219,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
|
||||||
var end = GetIterator(begin, raw.Length);
|
var end = GetIterator(begin, raw.Length);
|
||||||
|
|
||||||
var resultEnd = UrlPathDecoder.Unescape(begin, end);
|
var resultEnd = UrlPathDecoder.Unescape(begin, end);
|
||||||
var result = begin.GetUtf8String(resultEnd);
|
var result = begin.GetUtf8String(ref resultEnd);
|
||||||
Assert.Equal(raw, result);
|
Assert.Equal(raw, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ using Microsoft.AspNetCore.Server.Kestrel;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Internal;
|
using Microsoft.AspNetCore.Server.Kestrel.Internal;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
|
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers
|
namespace Microsoft.AspNetCore.Testing
|
||||||
{
|
{
|
||||||
public class MockConnection : Connection, IDisposable
|
public class MockConnection : Connection, IDisposable
|
||||||
{
|
{
|
||||||
|
|
@ -18,7 +18,10 @@ namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers
|
||||||
{
|
{
|
||||||
ConnectionControl = this;
|
ConnectionControl = this;
|
||||||
RequestAbortedSource = new CancellationTokenSource();
|
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)
|
public override void Abort(Exception error = null)
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
|
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.KestrelTests.TestHelpers
|
namespace Microsoft.AspNetCore.Testing
|
||||||
{
|
{
|
||||||
public static class SocketInputExtensions
|
public static class SocketInputExtensions
|
||||||
{
|
{
|
||||||
Loading…
Reference in New Issue