Refactored to use the fields from the HttpMethods class

* Reacting to PR comments
This commit is contained in:
Mikael Mengistu 2016-09-29 12:19:26 -07:00 committed by GitHub
parent 310411075f
commit 12adc7de9d
2 changed files with 19 additions and 28 deletions

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Text; using System.Text;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Http;
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure 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; 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 Http10Version = "HTTP/1.0";
public const string Http11Version = "HTTP/1.1"; public const string Http11Version = "HTTP/1.1";
@ -49,14 +40,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
static MemoryPoolIteratorExtensions() static MemoryPoolIteratorExtensions()
{ {
_knownMethods[0] = Tuple.Create(_mask4Chars, _httpPutMethodLong, HttpPutMethod); _knownMethods[0] = Tuple.Create(_mask4Chars, _httpPutMethodLong, HttpMethods.Put);
_knownMethods[1] = Tuple.Create(_mask5Chars, _httpPostMethodLong, HttpPostMethod); _knownMethods[1] = Tuple.Create(_mask5Chars, _httpPostMethodLong, HttpMethods.Post);
_knownMethods[2] = Tuple.Create(_mask5Chars, _httpHeadMethodLong, HttpHeadMethod); _knownMethods[2] = Tuple.Create(_mask5Chars, _httpHeadMethodLong, HttpMethods.Head);
_knownMethods[3] = Tuple.Create(_mask6Chars, _httpTraceMethodLong, HttpTraceMethod); _knownMethods[3] = Tuple.Create(_mask6Chars, _httpTraceMethodLong, HttpMethods.Trace);
_knownMethods[4] = Tuple.Create(_mask6Chars, _httpPatchMethodLong, HttpPatchMethod); _knownMethods[4] = Tuple.Create(_mask6Chars, _httpPatchMethodLong, HttpMethods.Patch);
_knownMethods[5] = Tuple.Create(_mask7Chars, _httpDeleteMethodLong, HttpDeleteMethod); _knownMethods[5] = Tuple.Create(_mask7Chars, _httpDeleteMethodLong, HttpMethods.Delete);
_knownMethods[6] = Tuple.Create(_mask8Chars, _httpConnectMethodLong, HttpConnectMethod); _knownMethods[6] = Tuple.Create(_mask8Chars, _httpConnectMethodLong, HttpMethods.Connect);
_knownMethods[7] = Tuple.Create(_mask8Chars, _httpOptionsMethodLong, HttpOptionsMethod); _knownMethods[7] = Tuple.Create(_mask8Chars, _httpOptionsMethodLong, HttpMethods.Options);
} }
private unsafe static long GetAsciiStringAsLong(string str) private unsafe static long GetAsciiStringAsLong(string str)
@ -279,7 +270,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
if ((value & _mask4Chars) == _httpGetMethodLong) if ((value & _mask4Chars) == _httpGetMethodLong)
{ {
knownMethod = HttpGetMethod; knownMethod = HttpMethods.Get;
return true; return true;
} }
foreach (var x in _knownMethods) foreach (var x in _knownMethods)

View File

@ -432,15 +432,15 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
} }
[Theory] [Theory]
[InlineData("CONNECT / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpConnectMethod)] [InlineData("CONNECT / HTTP/1.1", ' ', true, "CONNECT")]
[InlineData("DELETE / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpDeleteMethod)] [InlineData("DELETE / HTTP/1.1", ' ', true, "DELETE")]
[InlineData("GET / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpGetMethod)] [InlineData("GET / HTTP/1.1", ' ', true, "GET")]
[InlineData("HEAD / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpHeadMethod)] [InlineData("HEAD / HTTP/1.1", ' ', true, "HEAD")]
[InlineData("PATCH / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpPatchMethod)] [InlineData("PATCH / HTTP/1.1", ' ', true, "PATCH")]
[InlineData("POST / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpPostMethod)] [InlineData("POST / HTTP/1.1", ' ', true, "POST")]
[InlineData("PUT / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpPutMethod)] [InlineData("PUT / HTTP/1.1", ' ', true, "PUT")]
[InlineData("OPTIONS / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpOptionsMethod)] [InlineData("OPTIONS / HTTP/1.1", ' ', true, "OPTIONS")]
[InlineData("TRACE / HTTP/1.1", ' ', true, MemoryPoolIteratorExtensions.HttpTraceMethod)] [InlineData("TRACE / HTTP/1.1", ' ', true, "TRACE")]
[InlineData("GET/ HTTP/1.1", ' ', false, null)] [InlineData("GET/ HTTP/1.1", ' ', false, null)]
[InlineData("get / HTTP/1.1", ' ', false, null)] [InlineData("get / HTTP/1.1", ' ', false, null)]
[InlineData("GOT / HTTP/1.1", ' ', false, null)] [InlineData("GOT / HTTP/1.1", ' ', false, null)]