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 System.Linq;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.Primitives;
|
using Microsoft.Extensions.Primitives;
|
||||||
|
using Microsoft.Net.Http.Headers;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
|
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)
|
public static unsafe long ParseContentLength(StringValues value)
|
||||||
{
|
{
|
||||||
var input = value.ToString();
|
long parsed;
|
||||||
var parsed = 0L;
|
if (!HeaderUtilities.TryParseInt64(new StringSegment(value.ToString()), out parsed))
|
||||||
|
|
||||||
fixed (char* ptr = input)
|
|
||||||
{
|
{
|
||||||
var ch = (ushort*)ptr;
|
ThrowInvalidContentLengthException(value);
|
||||||
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;
|
return parsed;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue