Move Int64 parsing logic to HttpAbstractions
This commit is contained in:
parent
ad2a00dbbd
commit
4da06e8acd
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue