-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Http.Sys: Clean up Request parsing errors #57531
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,7 @@ internal partial class RequestContext : | |
private bool _bodyCompleted; | ||
private IHeaderDictionary _responseHeaders = default!; | ||
private IHeaderDictionary? _responseTrailers; | ||
private ulong? _requestId; | ||
|
||
private Fields _initializedFields; | ||
|
||
|
@@ -98,11 +99,26 @@ private enum Fields | |
TraceIdentifier = 0x200, | ||
} | ||
|
||
protected internal void InitializeFeatures() | ||
protected internal bool InitializeFeatures() | ||
{ | ||
_initialized = true; | ||
|
||
Request = new Request(this); | ||
// Get the ID before creating the Request object as the Request ctor releases the native memory | ||
// We want the ID in case request processing fails and we need the ID to cancel the native request | ||
_requestId = RequestId; | ||
try | ||
{ | ||
Request = new Request(this); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.RequestParsingError(Logger, ex); | ||
// Synchronously calls Http.Sys and tells it to send an http response | ||
// No one has written to the response yet (haven't even created the response object below) | ||
Server.SendError(_requestId.Value, StatusCodes.Status400BadRequest, authChallenges: null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not immediately obvious that this is a safe place to call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a synchronous call, only state it needs from InitializeFeature is the request ID which we pass in. Would you like some sort of comment here mentioning it's a synchronous call to native code? |
||
return false; | ||
} | ||
|
||
Response = new Response(this); | ||
|
||
_features = new FeatureCollection(new StandardFeatureCollection(this)); | ||
|
@@ -124,6 +140,7 @@ protected internal void InitializeFeatures() | |
|
||
_responseStream = new ResponseStream(Response.Body, OnResponseStart); | ||
_responseHeaders = Response.Headers; | ||
return true; | ||
} | ||
|
||
private bool IsNotInitialized(Fields field) | ||
|
Uh oh!
There was an error while loading. Please reload this page.