Enum to singular

This commit is contained in:
Ben Adams 2016-07-22 22:19:50 +01:00
parent 0620ce5a2f
commit 51288e13f8
9 changed files with 62 additions and 62 deletions

View File

@ -14,69 +14,69 @@ namespace Microsoft.AspNetCore.Server.Kestrel
} }
internal static BadHttpRequestException GetException(RequestRejectionReasons reason) internal static BadHttpRequestException GetException(RequestRejectionReason reason)
{ {
BadHttpRequestException ex; BadHttpRequestException ex;
switch (reason) switch (reason)
{ {
case RequestRejectionReasons.MissingMethod: case RequestRejectionReason.MissingMethod:
ex = new BadHttpRequestException("Missing method."); ex = new BadHttpRequestException("Missing method.");
break; break;
case RequestRejectionReasons.InvalidMethod: case RequestRejectionReason.InvalidMethod:
ex = new BadHttpRequestException("Invalid method."); ex = new BadHttpRequestException("Invalid method.");
break; break;
case RequestRejectionReasons.MissingRequestTarget: case RequestRejectionReason.MissingRequestTarget:
ex = new BadHttpRequestException("Missing request target."); ex = new BadHttpRequestException("Missing request target.");
break; break;
case RequestRejectionReasons.MissingHTTPVersion: case RequestRejectionReason.MissingHTTPVersion:
ex = new BadHttpRequestException("Missing HTTP version."); ex = new BadHttpRequestException("Missing HTTP version.");
break; break;
case RequestRejectionReasons.UnrecognizedHTTPVersion: case RequestRejectionReason.UnrecognizedHTTPVersion:
ex = new BadHttpRequestException("Unrecognized HTTP version."); ex = new BadHttpRequestException("Unrecognized HTTP version.");
break; break;
case RequestRejectionReasons.MissingLFInRequestLine: case RequestRejectionReason.MissingLFInRequestLine:
ex = new BadHttpRequestException("Missing LF in request line."); ex = new BadHttpRequestException("Missing LF in request line.");
break; break;
case RequestRejectionReasons.HeadersCorruptedInvalidHeaderSequence: case RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence:
ex = new BadHttpRequestException("Headers corrupted, invalid header sequence."); ex = new BadHttpRequestException("Headers corrupted, invalid header sequence.");
break; break;
case RequestRejectionReasons.HeaderLineMustNotStartWithWhitespace: case RequestRejectionReason.HeaderLineMustNotStartWithWhitespace:
ex = new BadHttpRequestException("Header line must not start with whitespace."); ex = new BadHttpRequestException("Header line must not start with whitespace.");
break; break;
case RequestRejectionReasons.NoColonCharacterFoundInHeaderLine: case RequestRejectionReason.NoColonCharacterFoundInHeaderLine:
ex = new BadHttpRequestException("No ':' character found in header line."); ex = new BadHttpRequestException("No ':' character found in header line.");
break; break;
case RequestRejectionReasons.WhitespaceIsNotAllowedInHeaderName: case RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName:
ex = new BadHttpRequestException("Whitespace is not allowed in header name."); ex = new BadHttpRequestException("Whitespace is not allowed in header name.");
break; break;
case RequestRejectionReasons.HeaderLineMustEndInCRLFOnlyCRFound: case RequestRejectionReason.HeaderLineMustEndInCRLFOnlyCRFound:
ex = new BadHttpRequestException("Header line must end in CRLF; only CR found."); ex = new BadHttpRequestException("Header line must end in CRLF; only CR found.");
break; break;
case RequestRejectionReasons.HeaderValueLineFoldingNotSupported: case RequestRejectionReason.HeaderValueLineFoldingNotSupported:
ex = new BadHttpRequestException("Header value line folding not supported."); ex = new BadHttpRequestException("Header value line folding not supported.");
break; break;
case RequestRejectionReasons.MalformedRequestInvalidHeaders: case RequestRejectionReason.MalformedRequestInvalidHeaders:
ex = new BadHttpRequestException("Malformed request: invalid headers."); ex = new BadHttpRequestException("Malformed request: invalid headers.");
break; break;
case RequestRejectionReasons.UnexpectedEndOfRequestContent: case RequestRejectionReason.UnexpectedEndOfRequestContent:
ex = new BadHttpRequestException("Unexpected end of request content"); ex = new BadHttpRequestException("Unexpected end of request content.");
break; break;
case RequestRejectionReasons.BadChunkSuffix: case RequestRejectionReason.BadChunkSuffix:
ex = new BadHttpRequestException("Bad chunk suffix"); ex = new BadHttpRequestException("Bad chunk suffix.");
break; break;
case RequestRejectionReasons.BadChunkSizeData: case RequestRejectionReason.BadChunkSizeData:
ex = new BadHttpRequestException("Bad chunk size data"); ex = new BadHttpRequestException("Bad chunk size data.");
break; break;
case RequestRejectionReasons.ChunkedRequestIncomplete: case RequestRejectionReason.ChunkedRequestIncomplete:
ex = new BadHttpRequestException("Chunked request incomplete"); ex = new BadHttpRequestException("Chunked request incomplete.");
break; break;
case RequestRejectionReasons.PathContainsNullCharacters: case RequestRejectionReason.PathContainsNullCharacters:
ex = new BadHttpRequestException("The path contains null characters."); ex = new BadHttpRequestException("The path contains null characters.");
break; break;
case RequestRejectionReasons.InvalidCharactersInHeaderName: case RequestRejectionReason.InvalidCharactersInHeaderName:
ex = new BadHttpRequestException("Invalid characters in header name."); ex = new BadHttpRequestException("Invalid characters in header name.");
break; break;
case RequestRejectionReasons.NonAsciiOrNullCharactersInInputString: case RequestRejectionReason.NonAsciiOrNullCharactersInInputString:
ex = new BadHttpRequestException("The input string contains non-ASCII or null characters."); ex = new BadHttpRequestException("The input string contains non-ASCII or null characters.");
break; break;
default: default:
@ -86,15 +86,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel
return ex; return ex;
} }
internal static BadHttpRequestException GetException(RequestRejectionReasons reason, string value) internal static BadHttpRequestException GetException(RequestRejectionReason reason, string value)
{ {
BadHttpRequestException ex; BadHttpRequestException ex;
switch (reason) switch (reason)
{ {
case RequestRejectionReasons.MalformedRequestLineStatus: case RequestRejectionReason.MalformedRequestLineStatus:
ex = new BadHttpRequestException($"Malformed request: {value}"); ex = new BadHttpRequestException($"Malformed request: {value}");
break; break;
case RequestRejectionReasons.InvalidContentLength: case RequestRejectionReason.InvalidContentLength:
ex = new BadHttpRequestException($"Invalid content length: {value}"); ex = new BadHttpRequestException($"Invalid content length: {value}");
break; break;
default: default:

View File

@ -814,7 +814,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
if (method == null) if (method == null)
{ {
RejectRequest(RequestRejectionReasons.MissingMethod); RejectRequest(RequestRejectionReason.MissingMethod);
} }
// Note: We're not in the fast path any more (GetKnownMethod should have handled any HTTP Method we're aware of) // Note: We're not in the fast path any more (GetKnownMethod should have handled any HTTP Method we're aware of)
@ -823,7 +823,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
{ {
if (!IsValidTokenChar(method[i])) if (!IsValidTokenChar(method[i]))
{ {
RejectRequest(RequestRejectionReasons.InvalidMethod); RejectRequest(RequestRejectionReason.InvalidMethod);
} }
} }
} }
@ -868,7 +868,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
if (pathBegin.Peek() == ' ') if (pathBegin.Peek() == ' ')
{ {
RejectRequest(RequestRejectionReasons.MissingRequestTarget); RejectRequest(RequestRejectionReason.MissingRequestTarget);
} }
scan.Take(); scan.Take();
@ -890,11 +890,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
if (httpVersion == null) if (httpVersion == null)
{ {
RejectRequest(RequestRejectionReasons.MissingHTTPVersion); RejectRequest(RequestRejectionReason.MissingHTTPVersion);
} }
else if (httpVersion != "HTTP/1.0" && httpVersion != "HTTP/1.1") else if (httpVersion != "HTTP/1.0" && httpVersion != "HTTP/1.1")
{ {
RejectRequest(RequestRejectionReasons.UnrecognizedHTTPVersion); RejectRequest(RequestRejectionReason.UnrecognizedHTTPVersion);
} }
} }
@ -906,7 +906,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
} }
else if (next != '\n') else if (next != '\n')
{ {
RejectRequest(RequestRejectionReasons.MissingLFInRequestLine); RejectRequest(RequestRejectionReason.MissingLFInRequestLine);
} }
// URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11 // URIs are always encoded/escaped to ASCII https://tools.ietf.org/html/rfc3986#page-11
@ -1060,11 +1060,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
} }
// Headers don't end in CRLF line. // Headers don't end in CRLF line.
RejectRequest(RequestRejectionReasons.HeadersCorruptedInvalidHeaderSequence); RejectRequest(RequestRejectionReason.HeadersCorruptedInvalidHeaderSequence);
} }
else if (ch == ' ' || ch == '\t') else if (ch == ' ' || ch == '\t')
{ {
RejectRequest(RequestRejectionReasons.HeaderLineMustNotStartWithWhitespace); RejectRequest(RequestRejectionReason.HeaderLineMustNotStartWithWhitespace);
} }
var beginName = scan; var beginName = scan;
@ -1077,13 +1077,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
ch = scan.Take(); ch = scan.Take();
if (ch != ':') if (ch != ':')
{ {
RejectRequest(RequestRejectionReasons.NoColonCharacterFoundInHeaderLine); RejectRequest(RequestRejectionReason.NoColonCharacterFoundInHeaderLine);
} }
var validateName = beginName; var validateName = beginName;
if (validateName.Seek(ref _vectorSpaces, ref _vectorTabs, ref _vectorColons) != ':') if (validateName.Seek(ref _vectorSpaces, ref _vectorTabs, ref _vectorColons) != ':')
{ {
RejectRequest(RequestRejectionReasons.WhitespaceIsNotAllowedInHeaderName); RejectRequest(RequestRejectionReason.WhitespaceIsNotAllowedInHeaderName);
} }
var beginValue = scan; var beginValue = scan;
@ -1123,7 +1123,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
} }
else if (ch != '\n') else if (ch != '\n')
{ {
RejectRequest(RequestRejectionReasons.HeaderLineMustEndInCRLFOnlyCRFound); RejectRequest(RequestRejectionReason.HeaderLineMustEndInCRLFOnlyCRFound);
} }
var next = scan.Peek(); var next = scan.Peek();
@ -1150,7 +1150,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
// explaining that obsolete line folding is unacceptable, or replace // explaining that obsolete line folding is unacceptable, or replace
// each received obs-fold with one or more SP octets prior to // each received obs-fold with one or more SP octets prior to
// interpreting the field value or forwarding the message downstream. // interpreting the field value or forwarding the message downstream.
RejectRequest(RequestRejectionReasons.HeaderValueLineFoldingNotSupported); RejectRequest(RequestRejectionReason.HeaderValueLineFoldingNotSupported);
} }
// Trim trailing whitespace from header value by repeatedly advancing to next // Trim trailing whitespace from header value by repeatedly advancing to next
@ -1206,18 +1206,18 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
private void ThrowResponseAbortedException() private void ThrowResponseAbortedException()
{ {
throw new ObjectDisposedException( throw new ObjectDisposedException(
"The response has been aborted due to an unhandled application exception.", "The response has been aborted due to an unhandled application exception.",
_applicationException); _applicationException);
} }
public void RejectRequest(RequestRejectionReasons reason) public void RejectRequest(RequestRejectionReason reason)
{ {
var ex = BadHttpRequestException.GetException(reason); var ex = BadHttpRequestException.GetException(reason);
SetBadRequestState(ex); SetBadRequestState(ex);
throw ex; throw ex;
} }
public void RejectRequest(RequestRejectionReasons reason, string value) public void RejectRequest(RequestRejectionReason reason, string value)
{ {
var ex = BadHttpRequestException.GetException(reason, value); var ex = BadHttpRequestException.GetException(reason, value);
SetBadRequestState(ex); SetBadRequestState(ex);

View File

@ -4903,7 +4903,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
{ {
if (!AsciiUtilities.TryGetAsciiString(ptr, keyBuffer, keyLength)) if (!AsciiUtilities.TryGetAsciiString(ptr, keyBuffer, keyLength))
{ {
throw BadHttpRequestException.GetException(RequestRejectionReasons.InvalidCharactersInHeaderName); throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidCharactersInHeaderName);
} }
} }
} }

View File

@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
if (requestLineStatus != RequestLineStatus.Done) if (requestLineStatus != RequestLineStatus.Done)
{ {
RejectRequest(RequestRejectionReasons.MalformedRequestLineStatus, requestLineStatus.ToString()); RejectRequest(RequestRejectionReason.MalformedRequestLineStatus, requestLineStatus.ToString());
} }
break; break;
@ -70,7 +70,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
// sent immediately before the a FIN from the client. // sent immediately before the a FIN from the client.
if (!TakeMessageHeaders(SocketInput, FrameRequestHeaders)) if (!TakeMessageHeaders(SocketInput, FrameRequestHeaders))
{ {
RejectRequest(RequestRejectionReasons.MalformedRequestInvalidHeaders); RejectRequest(RequestRejectionReason.MalformedRequestInvalidHeaders);
} }
break; break;

View File

@ -123,7 +123,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
long contentLength; long contentLength;
if (!long.TryParse(unparsedContentLength, out contentLength) || contentLength < 0) if (!long.TryParse(unparsedContentLength, out contentLength) || contentLength < 0)
{ {
context.RejectRequest(RequestRejectionReasons.InvalidContentLength, unparsedContentLength); context.RejectRequest(RequestRejectionReason.InvalidContentLength, unparsedContentLength);
} }
else else
{ {
@ -185,7 +185,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
_inputLength -= actual; _inputLength -= actual;
if (actual == 0) if (actual == 0)
{ {
_context.RejectRequest(RequestRejectionReasons.UnexpectedEndOfRequestContent); _context.RejectRequest(RequestRejectionReason.UnexpectedEndOfRequestContent);
} }
return new ValueTask<int>(actual); return new ValueTask<int>(actual);
} }
@ -201,7 +201,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
_inputLength -= actual; _inputLength -= actual;
if (actual == 0) if (actual == 0)
{ {
_context.RejectRequest(RequestRejectionReasons.UnexpectedEndOfRequestContent); _context.RejectRequest(RequestRejectionReason.UnexpectedEndOfRequestContent);
} }
return actual; return actual;
@ -249,7 +249,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
} }
else if (fin) else if (fin)
{ {
_context.RejectRequest(RequestRejectionReasons.ChunkedRequestIncomplete); _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete);
} }
await input; await input;
@ -267,7 +267,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
} }
else if (fin) else if (fin)
{ {
_context.RejectRequest(RequestRejectionReasons.ChunkedRequestIncomplete); _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete);
} }
await input; await input;
@ -289,7 +289,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
} }
else if (fin) else if (fin)
{ {
_context.RejectRequest(RequestRejectionReasons.ChunkedRequestIncomplete); _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete);
} }
await input; await input;
@ -307,7 +307,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
} }
else if (fin) else if (fin)
{ {
_context.RejectRequest(RequestRejectionReasons.ChunkedRequestIncomplete); _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete);
} }
await input; await input;
@ -327,7 +327,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
} }
else if (fin) else if (fin)
{ {
_context.RejectRequest(RequestRejectionReasons.ChunkedRequestIncomplete); _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete);
} }
await input; await input;
@ -345,7 +345,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
} }
else else
{ {
_context.RejectRequest(RequestRejectionReasons.ChunkedRequestIncomplete); _context.RejectRequest(RequestRejectionReason.ChunkedRequestIncomplete);
} }
} }
@ -504,7 +504,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
} }
else else
{ {
_context.RejectRequest(RequestRejectionReasons.BadChunkSuffix); _context.RejectRequest(RequestRejectionReason.BadChunkSuffix);
} }
} }
finally finally
@ -560,7 +560,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
} }
} }
_context.RejectRequest(RequestRejectionReasons.BadChunkSizeData); _context.RejectRequest(RequestRejectionReason.BadChunkSizeData);
return -1; // can't happen, but compiler complains return -1; // can't happen, but compiler complains
} }

View File

@ -3,7 +3,7 @@
namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
{ {
public enum RequestRejectionReasons public enum RequestRejectionReason
{ {
MissingMethod, MissingMethod,
InvalidMethod, InvalidMethod,

View File

@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
if (byte1 == 0) if (byte1 == 0)
{ {
throw BadHttpRequestException.GetException(RequestRejectionReasons.PathContainsNullCharacters); throw BadHttpRequestException.GetException(RequestRejectionReason.PathContainsNullCharacters);
} }
if (byte1 == -1) if (byte1 == -1)

View File

@ -116,7 +116,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure
{ {
if (!AsciiUtilities.TryGetAsciiString(block.DataFixedPtr + inputOffset, output + outputOffset, following)) if (!AsciiUtilities.TryGetAsciiString(block.DataFixedPtr + inputOffset, output + outputOffset, following))
{ {
throw BadHttpRequestException.GetException(RequestRejectionReasons.NonAsciiOrNullCharactersInInputString); throw BadHttpRequestException.GetException(RequestRejectionReason.NonAsciiOrNullCharactersInInputString);
} }
outputOffset += following; outputOffset += following;

View File

@ -450,7 +450,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Internal.Http
{{ {{
if (!AsciiUtilities.TryGetAsciiString(ptr, keyBuffer, keyLength)) if (!AsciiUtilities.TryGetAsciiString(ptr, keyBuffer, keyLength))
{{ {{
throw BadHttpRequestException.GetException(RequestRejectionReasons.InvalidCharactersInHeaderName); throw BadHttpRequestException.GetException(RequestRejectionReason.InvalidCharactersInHeaderName);
}} }}
}} }}
}} }}