Merge branch 'benaadams/enum-rather-than-string' into dev

This commit is contained in:
Stephen Halter 2016-07-25 10:30:33 -07:00
commit 3a67cb9df5
6 changed files with 30 additions and 26 deletions

View File

@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
private bool _autoChunk; private bool _autoChunk;
protected Exception _applicationException; protected Exception _applicationException;
private HttpVersionType _httpVersion; protected HttpVersion _httpVersion;
private readonly string _pathBase; private readonly string _pathBase;
@ -89,11 +89,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
{ {
get get
{ {
if (_httpVersion == HttpVersionType.Http11) if (_httpVersion == Http.HttpVersion.Http11)
{ {
return "HTTP/1.1"; return "HTTP/1.1";
} }
if (_httpVersion == HttpVersionType.Http10) if (_httpVersion == Http.HttpVersion.Http10)
{ {
return "HTTP/1.0"; return "HTTP/1.0";
} }
@ -104,15 +104,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
{ {
if (value == "HTTP/1.1") if (value == "HTTP/1.1")
{ {
_httpVersion = HttpVersionType.Http11; _httpVersion = Http.HttpVersion.Http11;
} }
else if (value == "HTTP/1.0") else if (value == "HTTP/1.0")
{ {
_httpVersion = HttpVersionType.Http10; _httpVersion = Http.HttpVersion.Http10;
} }
else else
{ {
_httpVersion = HttpVersionType.Unset; _httpVersion = Http.HttpVersion.Unset;
} }
} }
} }
@ -290,7 +290,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
PathBase = null; PathBase = null;
Path = null; Path = null;
QueryString = null; QueryString = null;
_httpVersion = HttpVersionType.Unset; _httpVersion = Http.HttpVersion.Unset;
StatusCode = 200; StatusCode = 200;
ReasonPhrase = null; ReasonPhrase = null;
@ -547,7 +547,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
} }
StringValues expect; StringValues expect;
if (_httpVersion == HttpVersionType.Http11 && if (_httpVersion == Http.HttpVersion.Http11 &&
RequestHeaders.TryGetValue("Expect", out expect) && RequestHeaders.TryGetValue("Expect", out expect) &&
(expect.FirstOrDefault() ?? "").Equals("100-continue", StringComparison.OrdinalIgnoreCase)) (expect.FirstOrDefault() ?? "").Equals("100-continue", StringComparison.OrdinalIgnoreCase))
{ {
@ -749,7 +749,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
// //
// A server MUST NOT send a response containing Transfer-Encoding unless the corresponding // A server MUST NOT send a response containing Transfer-Encoding unless the corresponding
// request indicates HTTP/1.1 (or later). // request indicates HTTP/1.1 (or later).
if (_httpVersion == HttpVersionType.Http11) if (_httpVersion == Http.HttpVersion.Http11)
{ {
_autoChunk = true; _autoChunk = true;
responseHeaders.SetRawTransferEncoding("chunked", _bytesTransferEncodingChunked); responseHeaders.SetRawTransferEncoding("chunked", _bytesTransferEncodingChunked);
@ -761,11 +761,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
} }
} }
if (!_keepAlive && !hasConnection && _httpVersion != HttpVersionType.Http10) if (!_keepAlive && !hasConnection && _httpVersion != Http.HttpVersion.Http10)
{ {
responseHeaders.SetRawConnection("close", _bytesConnectionClose); responseHeaders.SetRawConnection("close", _bytesConnectionClose);
} }
else if (_keepAlive && !hasConnection && _httpVersion == HttpVersionType.Http10) else if (_keepAlive && !hasConnection && _httpVersion == Http.HttpVersion.Http10)
{ {
responseHeaders.SetRawConnection("keep-alive", _bytesConnectionKeepAlive); responseHeaders.SetRawConnection("keep-alive", _bytesConnectionKeepAlive);
} }
@ -1235,13 +1235,6 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
Log.ApplicationError(ConnectionId, ex); Log.ApplicationError(ConnectionId, ex);
} }
private enum HttpVersionType
{
Unset = -1,
Http10 = 0,
Http11 = 1
}
protected enum RequestLineStatus protected enum RequestLineStatus
{ {
Empty, Empty,

View File

@ -81,7 +81,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
if (!_requestProcessingStopping) if (!_requestProcessingStopping)
{ {
var messageBody = MessageBody.For(HttpVersion, FrameRequestHeaders, this); var messageBody = MessageBody.For(_httpVersion, FrameRequestHeaders, this);
_keepAlive = messageBody.RequestKeepAlive; _keepAlive = messageBody.RequestKeepAlive;
InitializeStreams(messageBody); InitializeStreams(messageBody);

View File

@ -0,0 +1,12 @@
// 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.
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
{
public enum HttpVersion
{
Unset = -1,
Http10 = 0,
Http11 = 1
}
}

View File

@ -97,13 +97,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
public abstract ValueTask<int> ReadAsyncImplementation(ArraySegment<byte> buffer, CancellationToken cancellationToken); public abstract ValueTask<int> ReadAsyncImplementation(ArraySegment<byte> buffer, CancellationToken cancellationToken);
public static MessageBody For( public static MessageBody For(
string httpVersion, HttpVersion httpVersion,
FrameRequestHeaders headers, FrameRequestHeaders headers,
Frame context) Frame context)
{ {
// see also http://tools.ietf.org/html/rfc2616#section-4.4 // see also http://tools.ietf.org/html/rfc2616#section-4.4
var keepAlive = httpVersion != HttpVersion.Http10;
var keepAlive = httpVersion != "HTTP/1.0";
var connection = headers.HeaderConnection.ToString(); var connection = headers.HeaderConnection.ToString();
if (connection.Length > 0) if (connection.Length > 0)

View File

@ -502,7 +502,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
var frame = new Frame<object>(application: null, context: connectionContext); var frame = new Frame<object>(application: null, context: connectionContext);
frame.InitializeHeaders(); frame.InitializeHeaders();
var messageBody = MessageBody.For("HTTP/1.1", (FrameRequestHeaders)frame.RequestHeaders, frame); var messageBody = MessageBody.For(HttpVersion.Http11, (FrameRequestHeaders)frame.RequestHeaders, frame);
frame.InitializeStreams(messageBody); frame.InitializeStreams(messageBody);
var originalRequestBody = frame.RequestBody; var originalRequestBody = frame.RequestBody;

View File

@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
{ {
using (var input = new TestInput()) using (var input = new TestInput())
{ {
var body = MessageBody.For("HTTP/1.0", new FrameRequestHeaders(), input.FrameContext); var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders(), input.FrameContext);
var stream = new FrameRequestStream(); var stream = new FrameRequestStream();
stream.StartAcceptingReads(body); stream.StartAcceptingReads(body);
@ -40,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
{ {
using (var input = new TestInput()) using (var input = new TestInput())
{ {
var body = MessageBody.For("HTTP/1.0", new FrameRequestHeaders(), input.FrameContext); var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders(), input.FrameContext);
var stream = new FrameRequestStream(); var stream = new FrameRequestStream();
stream.StartAcceptingReads(body); stream.StartAcceptingReads(body);
@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
{ {
using (var input = new TestInput()) using (var input = new TestInput())
{ {
var body = MessageBody.For("HTTP/1.0", new FrameRequestHeaders(), input.FrameContext); var body = MessageBody.For(HttpVersion.Http10, new FrameRequestHeaders(), input.FrameContext);
var stream = new FrameRequestStream(); var stream = new FrameRequestStream();
stream.StartAcceptingReads(body); stream.StartAcceptingReads(body);