-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Move BadHttpRequestException to Http.Abstractions #20339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7324562
Add new BadHttpRequestException to Http Abstractions
cado1982 a3e4b2c
Update Kestrel to use new BadHttpRequestException from Http Abstractions
cado1982 0cd3e6f
Update IIS to use new BadHttpRequestException from Http Abstractions
cado1982 701d799
Add missing using directive to qualify StatusCodes
cado1982 9df44c5
Regenerate reference assemblies
cado1982 1f60a99
Revert c7a356 f81b48 7b5611 aaea8b
cado1982 68025ba
Fix merge conflicts
cado1982 5247c0a
Alter BadHttpRequestException to inherit from shared Http Abstraction…
cado1982 a905b04
Regenerate reference assemblies
cado1982 f150c86
Further refactorings for IIS and Kestrel BadHttpRequestException
cado1982 9ae2034
Regenerate reference assemblies
cado1982 32cf37c
Fix some usages of BadHttpRequestException and add using statements
cado1982 cfd0cef
Merge branch 'master' into temp-11208
cado1982 1d2d166
Change test from ThrowsAny to ThrowsAnyAsync
cado1982 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.IO; | ||
|
||
namespace Microsoft.AspNetCore.Http | ||
{ | ||
/// <summary> | ||
/// Represents an HTTP request error | ||
/// </summary> | ||
public class BadHttpRequestException : IOException | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="BadHttpRequestException"/> class. | ||
/// </summary> | ||
/// <param name="message">The message to associate with this exception.</param> | ||
/// <param name="statusCode">The HTTP status code to associate with this exception.</param> | ||
public BadHttpRequestException(string message, int statusCode) | ||
: base(message) | ||
{ | ||
StatusCode = statusCode; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="BadHttpRequestException"/> class with the <see cref="StatusCode"/> set to 400 Bad Request. | ||
/// </summary> | ||
/// <param name="message">The message to associate with this exception</param> | ||
public BadHttpRequestException(string message) | ||
: base(message) | ||
{ | ||
StatusCode = StatusCodes.Status400BadRequest; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="BadHttpRequestException"/> class. | ||
/// </summary> | ||
/// <param name="message">The message to associate with this exception.</param> | ||
/// <param name="statusCode">The HTTP status code to associate with this exception.</param> | ||
/// <param name="innerException">The inner exception to associate with this exception</param> | ||
public BadHttpRequestException(string message, int statusCode, Exception innerException) | ||
: base(message, innerException) | ||
{ | ||
StatusCode = statusCode; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="BadHttpRequestException"/> class with the <see cref="StatusCode"/> set to 400 Bad Request. | ||
/// </summary> | ||
/// <param name="message">The message to associate with this exception</param> | ||
/// <param name="innerException">The inner exception to associate with this exception</param> | ||
public BadHttpRequestException(string message, Exception innerException) | ||
: base(message, innerException) | ||
{ | ||
StatusCode = StatusCodes.Status400BadRequest; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the HTTP status code for this exception. | ||
/// </summary> | ||
public int StatusCode { get; } | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,24 @@ | ||
// 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. | ||
|
||
using System; | ||
using System.IO; | ||
using System.Runtime.CompilerServices; | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace Microsoft.AspNetCore.Server.IIS | ||
{ | ||
public sealed class BadHttpRequestException : IOException | ||
[Obsolete("Moved to Microsoft.AspNetCore.Http.BadHttpRequestException")] | ||
public sealed class BadHttpRequestException : Microsoft.AspNetCore.Http.BadHttpRequestException | ||
{ | ||
private BadHttpRequestException(string message, int statusCode, RequestRejectionReason reason) | ||
: base(message) | ||
internal BadHttpRequestException(string message, int statusCode, RequestRejectionReason reason) | ||
: base(message, statusCode) | ||
{ | ||
StatusCode = statusCode; | ||
Reason = reason; | ||
} | ||
|
||
public int StatusCode { get; } | ||
Tratcher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public new int StatusCode { get => base.StatusCode; } | ||
|
||
internal RequestRejectionReason Reason { get; } | ||
|
||
internal static void Throw(RequestRejectionReason reason) | ||
{ | ||
throw GetException(reason); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
internal static BadHttpRequestException GetException(RequestRejectionReason reason) | ||
{ | ||
BadHttpRequestException ex; | ||
switch (reason) | ||
{ | ||
case RequestRejectionReason.RequestBodyTooLarge: | ||
ex = new BadHttpRequestException(CoreStrings.BadRequest_RequestBodyTooLarge, StatusCodes.Status413PayloadTooLarge, reason); | ||
break; | ||
default: | ||
ex = new BadHttpRequestException(CoreStrings.BadRequest, StatusCodes.Status400BadRequest, reason); | ||
break; | ||
} | ||
return ex; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// 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. | ||
|
||
using System; | ||
using System.IO; | ||
using System.Runtime.CompilerServices; | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace Microsoft.AspNetCore.Server.IIS | ||
{ | ||
internal static class IISBadHttpRequestException | ||
{ | ||
internal static void Throw(RequestRejectionReason reason) | ||
{ | ||
throw GetException(reason); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
#pragma warning disable CS0618 // Type or member is obsolete | ||
internal static BadHttpRequestException GetException(RequestRejectionReason reason) | ||
{ | ||
BadHttpRequestException ex; | ||
switch (reason) | ||
{ | ||
case RequestRejectionReason.RequestBodyTooLarge: | ||
ex = new BadHttpRequestException(CoreStrings.BadRequest_RequestBodyTooLarge, StatusCodes.Status413PayloadTooLarge, reason); | ||
break; | ||
default: | ||
ex = new BadHttpRequestException(CoreStrings.BadRequest, StatusCodes.Status400BadRequest, reason); | ||
break; | ||
} | ||
return ex; | ||
} | ||
#pragma warning restore CS0618 // Type or member is obsolete | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.