-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Use examined rather than consumed for content length of body. #8223
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
10 commits
Select commit
Hold shift + click to select a range
c3556da
Need a similar solution that http2 has
jkotalik 62cbe32
Prototype of fix
jkotalik b963405
I hate this solution with a passion but whatever
jkotalik 781f611
bodyReader
jkotalik 6cd36ef
Make Read/Advance throw appropriately
jkotalik 6d09e14
Set isReading in one more place
jkotalik e43f889
React to corefx changes
jkotalik 6eaeb7e
Feedback
jkotalik 14af05d
Feedback:
jkotalik 6c9b43e
fb
jkotalik 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
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 |
---|---|---|
|
@@ -727,6 +727,170 @@ await connection.ReceiveEnd( | |
} | ||
} | ||
|
||
[Fact] | ||
public async Task ContentLengthReadAsyncPipeReaderBufferRequestBody() | ||
{ | ||
var testContext = new TestServiceContext(LoggerFactory); | ||
|
||
using (var server = new TestServer(async httpContext => | ||
{ | ||
var readResult = await httpContext.Request.BodyReader.ReadAsync(); | ||
// This will hang if 0 content length is not assumed by the server | ||
Assert.Equal(5, readResult.Buffer.Length); | ||
httpContext.Request.BodyReader.AdvanceTo(readResult.Buffer.Start, readResult.Buffer.End); | ||
readResult = await httpContext.Request.BodyReader.ReadAsync(); | ||
Assert.Equal(5, readResult.Buffer.Length); | ||
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. Do you have any tests that attempt more than one read after getting a completed read result? |
||
|
||
}, testContext)) | ||
{ | ||
using (var connection = server.CreateConnection()) | ||
{ | ||
await connection.SendAll( | ||
"POST / HTTP/1.0", | ||
"Host:", | ||
"Content-Length: 5", | ||
"", | ||
"hello"); | ||
await connection.ReceiveEnd( | ||
"HTTP/1.1 200 OK", | ||
"Connection: close", | ||
$"Date: {testContext.DateHeaderValue}", | ||
"Content-Length: 0", | ||
"", | ||
""); | ||
} | ||
|
||
await server.StopAsync(); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task ContentLengthReadAsyncPipeReaderBufferRequestBodyMultipleTimes() | ||
{ | ||
var testContext = new TestServiceContext(LoggerFactory); | ||
|
||
using (var server = new TestServer(async httpContext => | ||
{ | ||
var readResult = await httpContext.Request.BodyReader.ReadAsync(); | ||
// This will hang if 0 content length is not assumed by the server | ||
Assert.Equal(5, readResult.Buffer.Length); | ||
httpContext.Request.BodyReader.AdvanceTo(readResult.Buffer.Start, readResult.Buffer.End); | ||
|
||
for (var i = 0; i < 2; i++) | ||
{ | ||
readResult = await httpContext.Request.BodyReader.ReadAsync(); | ||
Assert.Equal(5, readResult.Buffer.Length); | ||
httpContext.Request.BodyReader.AdvanceTo(readResult.Buffer.Start, readResult.Buffer.End); | ||
} | ||
}, testContext)) | ||
{ | ||
using (var connection = server.CreateConnection()) | ||
{ | ||
await connection.SendAll( | ||
"POST / HTTP/1.0", | ||
"Host:", | ||
"Content-Length: 5", | ||
"", | ||
"hello"); | ||
await connection.ReceiveEnd( | ||
"HTTP/1.1 200 OK", | ||
"Connection: close", | ||
$"Date: {testContext.DateHeaderValue}", | ||
"Content-Length: 0", | ||
"", | ||
""); | ||
} | ||
|
||
await server.StopAsync(); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task ContentLengthReadAsyncSingleBytesAtATime() | ||
{ | ||
var testContext = new TestServiceContext(LoggerFactory); | ||
var tcs = new TaskCompletionSource<object>(); | ||
var tcs2 = new TaskCompletionSource<object>(); | ||
using (var server = new TestServer(async httpContext => | ||
{ | ||
var readResult = await httpContext.Request.BodyReader.ReadAsync(); | ||
Assert.Equal(3, readResult.Buffer.Length); | ||
tcs.SetResult(null); | ||
|
||
httpContext.Request.BodyReader.AdvanceTo(readResult.Buffer.Start, readResult.Buffer.End); | ||
|
||
readResult = await httpContext.Request.BodyReader.ReadAsync(); | ||
httpContext.Request.BodyReader.AdvanceTo(readResult.Buffer.Start, readResult.Buffer.End); | ||
tcs2.SetResult(null); | ||
|
||
readResult = await httpContext.Request.BodyReader.ReadAsync(); | ||
Assert.Equal(5, readResult.Buffer.Length); | ||
|
||
}, testContext)) | ||
{ | ||
using (var connection = server.CreateConnection()) | ||
{ | ||
await connection.Send( | ||
"POST / HTTP/1.0", | ||
"Host:", | ||
"Content-Length: 5", | ||
"", | ||
"fun"); | ||
await tcs.Task; | ||
await connection.Send( | ||
"n"); | ||
await tcs2.Task; | ||
await connection.Send( | ||
"y"); | ||
await connection.ReceiveEnd( | ||
"HTTP/1.1 200 OK", | ||
"Connection: close", | ||
$"Date: {testContext.DateHeaderValue}", | ||
"Content-Length: 0", | ||
"", | ||
""); | ||
} | ||
|
||
await server.StopAsync(); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task ContentLengthDoesNotConsumeEntireBufferDoesNotThrow() | ||
{ | ||
var testContext = new TestServiceContext(LoggerFactory); | ||
using (var server = new TestServer(async httpContext => | ||
{ | ||
var readResult = await httpContext.Request.BodyReader.ReadAsync(); | ||
|
||
httpContext.Request.BodyReader.AdvanceTo(readResult.Buffer.Start, readResult.Buffer.End); | ||
|
||
readResult = await httpContext.Request.BodyReader.ReadAsync(); | ||
httpContext.Request.BodyReader.AdvanceTo(readResult.Buffer.Slice(1).Start, readResult.Buffer.End); | ||
}, testContext)) | ||
{ | ||
using (var connection = server.CreateConnection()) | ||
{ | ||
await connection.SendAll( | ||
"POST / HTTP/1.0", | ||
"Host:", | ||
"Content-Length: 5", | ||
"", | ||
"funny"); | ||
|
||
await connection.ReceiveEnd( | ||
"HTTP/1.1 200 OK", | ||
"Connection: close", | ||
$"Date: {testContext.DateHeaderValue}", | ||
"Content-Length: 0", | ||
"", | ||
""); | ||
} | ||
|
||
await server.StopAsync(); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task ConnectionClosesWhenFinReceivedBeforeRequestCompletes() | ||
{ | ||
|
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.