Пример #1
0
 internal BadHttpRequestException(string message, int statusCode, RequestRejectionReason reason)
     : base(message, statusCode)
 {
     Reason = reason;
 }
 internal static void Throw(RequestRejectionReason reason, HttpMethod method)
 => throw GetException(reason, method.ToString().ToUpperInvariant());
#pragma warning disable CS0618 // Type or member is obsolete
    internal static BadHttpRequestException GetException(RequestRejectionReason reason)
    {
        BadHttpRequestException ex;

        switch (reason)
        {
        case RequestRejectionReason.InvalidRequestHeadersNoCRLF:
            ex = new BadHttpRequestException(CoreStrings.BadRequest_InvalidRequestHeadersNoCRLF, StatusCodes.Status400BadRequest, reason);
            break;

        case RequestRejectionReason.InvalidRequestLine:
            ex = new BadHttpRequestException(CoreStrings.BadRequest_InvalidRequestLine, StatusCodes.Status400BadRequest, reason);
            break;

        case RequestRejectionReason.MalformedRequestInvalidHeaders:
            ex = new BadHttpRequestException(CoreStrings.BadRequest_MalformedRequestInvalidHeaders, StatusCodes.Status400BadRequest, reason);
            break;

        case RequestRejectionReason.MultipleContentLengths:
            ex = new BadHttpRequestException(CoreStrings.BadRequest_MultipleContentLengths, StatusCodes.Status400BadRequest, reason);
            break;

        case RequestRejectionReason.UnexpectedEndOfRequestContent:
            ex = new BadHttpRequestException(CoreStrings.BadRequest_UnexpectedEndOfRequestContent, StatusCodes.Status400BadRequest, reason);
            break;

        case RequestRejectionReason.BadChunkSuffix:
            ex = new BadHttpRequestException(CoreStrings.BadRequest_BadChunkSuffix, StatusCodes.Status400BadRequest, reason);
            break;

        case RequestRejectionReason.BadChunkSizeData:
            ex = new BadHttpRequestException(CoreStrings.BadRequest_BadChunkSizeData, StatusCodes.Status400BadRequest, reason);
            break;

        case RequestRejectionReason.ChunkedRequestIncomplete:
            ex = new BadHttpRequestException(CoreStrings.BadRequest_ChunkedRequestIncomplete, StatusCodes.Status400BadRequest, reason);
            break;

        case RequestRejectionReason.InvalidCharactersInHeaderName:
            ex = new BadHttpRequestException(CoreStrings.BadRequest_InvalidCharactersInHeaderName, StatusCodes.Status400BadRequest, reason);
            break;

        case RequestRejectionReason.RequestLineTooLong:
            ex = new BadHttpRequestException(CoreStrings.BadRequest_RequestLineTooLong, StatusCodes.Status414UriTooLong, reason);
            break;

        case RequestRejectionReason.HeadersExceedMaxTotalSize:
            ex = new BadHttpRequestException(CoreStrings.BadRequest_HeadersExceedMaxTotalSize, StatusCodes.Status431RequestHeaderFieldsTooLarge, reason);
            break;

        case RequestRejectionReason.TooManyHeaders:
            ex = new BadHttpRequestException(CoreStrings.BadRequest_TooManyHeaders, StatusCodes.Status431RequestHeaderFieldsTooLarge, reason);
            break;

        case RequestRejectionReason.RequestHeadersTimeout:
            ex = new BadHttpRequestException(CoreStrings.BadRequest_RequestHeadersTimeout, StatusCodes.Status408RequestTimeout, reason);
            break;

        case RequestRejectionReason.RequestBodyTimeout:
            ex = new BadHttpRequestException(CoreStrings.BadRequest_RequestBodyTimeout, StatusCodes.Status408RequestTimeout, reason);
            break;

        case RequestRejectionReason.OptionsMethodRequired:
            ex = new BadHttpRequestException(CoreStrings.BadRequest_MethodNotAllowed, StatusCodes.Status405MethodNotAllowed, reason, HttpMethod.Options);
            break;

        case RequestRejectionReason.ConnectMethodRequired:
            ex = new BadHttpRequestException(CoreStrings.BadRequest_MethodNotAllowed, StatusCodes.Status405MethodNotAllowed, reason, HttpMethod.Connect);
            break;

        case RequestRejectionReason.MissingHostHeader:
            ex = new BadHttpRequestException(CoreStrings.BadRequest_MissingHostHeader, StatusCodes.Status400BadRequest, reason);
            break;

        case RequestRejectionReason.MultipleHostHeaders:
            ex = new BadHttpRequestException(CoreStrings.BadRequest_MultipleHostHeaders, StatusCodes.Status400BadRequest, reason);
            break;

        case RequestRejectionReason.InvalidHostHeader:
            ex = new BadHttpRequestException(CoreStrings.BadRequest_InvalidHostHeader, StatusCodes.Status400BadRequest, reason);
            break;

        default:
            ex = new BadHttpRequestException(CoreStrings.BadRequest, StatusCodes.Status400BadRequest, reason);
            break;
        }
        return(ex);
    }
 internal static void Throw(RequestRejectionReason reason, StringValues detail)
 {
     throw GetException(reason, detail.ToString());
 }
 internal static void Throw(RequestRejectionReason reason)
 {
     throw GetException(reason);
 }
Пример #6
0
 internal static void Throw(RequestRejectionReason reason, in StringValues detail)
 internal static void Throw(RequestRejectionReason reason, string detail)
 {
     throw GetException(reason, detail);
 }
Пример #8
0
 private unsafe BadHttpRequestException GetInvalidRequestException(RequestRejectionReason reason, byte *detail, int length)
 {
     return(BadHttpRequestException.GetException(reason, ""));
 }
Пример #9
0
 private BadHttpRequestException(string message, int statusCode, RequestRejectionReason reason)
     : this(message, statusCode, reason, null)
 {
 }
Пример #10
0
 private void RejectRequest(RequestRejectionReason reason)
 => throw BadHttpRequestException.GetException(reason);
 private static string GetRejectionReasonMessage(RequestRejectionReason reason, string detail)
 {
     return($"{reason.ToString()} : {detail}");
 }
 private static string GetRejectionReasonMessage(RequestRejectionReason reason)
 {
     return(reason.ToString());
 }
 public static void Throw(RequestRejectionReason reason, string method)
 => throw GetException(reason, method.ToUpperInvariant());
 private BadHttpRequestException(string message, int statusCode, RequestRejectionReason reason)
     : base(message)
 {
     StatusCode = statusCode;
     Reason     = reason;
 }