Skip to content

Throw BadHttpRequestException in HttpSys #24213

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 4 commits into from
Jul 30, 2020

Conversation

Kahbazi
Copy link
Member

@Kahbazi Kahbazi commented Jul 22, 2020

Fixes #20688

@ghost ghost added the area-servers label Jul 22, 2020
Copy link
Member

@halter73 halter73 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. It better matches Kestrel's and IIS in-proc's behavior.

Copy link
Member

@Tratcher Tratcher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only covers half of #20688 so far. The other half is to catch the exception and return that status code. That would probobly happen here:

catch (Exception ex)
{
Logger.LogError(LoggerEventIds.RequestProcessError, ex, "ProcessRequestAsync");
application.DisposeContext(context, ex);
if (Response.HasStarted)
{
// HTTP/2 INTERNAL_ERROR = 0x2 https://tools.ietf.org/html/rfc7540#section-7
// Otherwise the default is Cancel = 0x8.
SetResetCode(2);
Abort();
}
else
{
// We haven't sent a response yet, try to send a 500 Internal Server Error
Response.Headers.IsReadOnly = false;
Response.Trailers.IsReadOnly = false;
Response.Headers.Clear();
Response.Trailers.Clear();
SetFatalResponse(500);

@Tratcher
Copy link
Member

Better. There should be existing tests for this scenario that you can update.

@Tratcher
Copy link
Member

@Tratcher
Copy link
Member

Nice. You're still missing test coverage for the new catch behavior. It's probably a combination of one of the tests you updated and something like this:

[ConditionalFact]
public async Task Server_AppException_ClientReset()
{
string address;
using (Utilities.CreateHttpServer(out address, httpContext =>
{
throw new InvalidOperationException();
}))
{
Task<string> requestTask = SendRequestAsync(address);
await Assert.ThrowsAsync<HttpRequestException>(async () => await requestTask);
// Do it again to make sure the server didn't crash
requestTask = SendRequestAsync(address);
await Assert.ThrowsAsync<HttpRequestException>(async () => await requestTask);
}
}

@Tratcher Tratcher merged commit 799014c into dotnet:master Jul 30, 2020
@Tratcher
Copy link
Member

Thanks

@Tratcher Tratcher added this to the 5.0.0-rc1 milestone Jul 30, 2020
@Kahbazi Kahbazi deleted the kahbazi/BadHttpRequestException branch July 31, 2020 03:51
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Have HttpSys throw BadHttpRequestException when request body limit is hit
4 participants