Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit 5e2999e

Browse files
committed
Move Int64 parsing logic to HttpAbstractions
1 parent b2d45c3 commit 5e2999e

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Linq;
88
using Microsoft.AspNetCore.Http;
99
using Microsoft.Extensions.Primitives;
10+
using Microsoft.Net.Http.Headers;
1011

1112
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
1213
{
@@ -234,31 +235,10 @@ public static void ValidateHeaderCharacters(string headerCharacters)
234235

235236
public static unsafe long ParseContentLength(StringValues value)
236237
{
237-
var input = value.ToString();
238-
var parsed = 0L;
239-
240-
fixed (char* ptr = input)
238+
long parsed;
239+
if (!HeaderUtilities.TryParseInt64(new StringSegment(value.ToString()), out parsed))
241240
{
242-
var ch = (ushort*)ptr;
243-
var end = ch + input.Length;
244-
245-
if (ch == end)
246-
{
247-
ThrowInvalidContentLengthException(value);
248-
}
249-
250-
ushort digit = 0;
251-
while (ch < end && (digit = (ushort)(*ch - 0x30)) <= 9)
252-
{
253-
parsed *= 10;
254-
parsed += digit;
255-
ch++;
256-
}
257-
258-
if (ch != end)
259-
{
260-
ThrowInvalidContentLengthException(value);
261-
}
241+
ThrowInvalidContentLengthException(value);
262242
}
263243

264244
return parsed;

0 commit comments

Comments
 (0)