Skip to content

Do not set HttpRequestMessage content when no PostData #3925

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 2 commits into from
Jul 8, 2019
Merged

Conversation

russcam
Copy link
Contributor

@russcam russcam commented Jul 5, 2019

This commit changes the HttpConnection to not set Content on HttpRequestMessage when there is no PostData. The check is performed inside of Request and RequestAsync to avoid creating any content instance and allocations.

Change length to default in TryComputeLength to match HttpContent implementation.

Pass RequestData through to _onStreamAvailable delegates so that HttpCompression, ConnectionSettings and PostData can be accessed on the passed instance.

Fixes #3907

This commit changes the HttpConnection to not set Content on HttpRequestMessage when there is no PostData. The check is performed inside of Request and RequestAsync to avoid creating any content instance and allocations.

Change length to default in TryComputeLength to match HttpContent implementation.

Pass RequestData through to _onStreamAvailable delegates so that HttpCompression, ConnectionSettings and PostData can be accessed on the passed instance.

Fixes #3907
Copy link
Member

@Mpdreamz Mpdreamz left a comment

Choose a reason for hiding this comment

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

I left some comments on changes made that differ from the reference implementations RequestDataContent is based on.

@@ -92,7 +91,7 @@ protected override async Task SerializeToStreamAsync(Stream stream, TransportCon
protected override bool TryComputeLength(out long length)
{
// We can't know the length of the content being pushed to the output stream.
length = -1;
length = default;
Copy link
Member

Choose a reason for hiding this comment

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

public override void Close()
{
_serializeToStreamTask.TrySetResult(true);
base.Close();
Copy link
Member

Choose a reason for hiding this comment

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

@@ -195,6 +197,8 @@ protected override void Dispose(bool disposing)
public override void EndWrite(IAsyncResult asyncResult) => _innerStream.EndWrite(asyncResult);

public override void WriteByte(byte value) => _innerStream.WriteByte(value);

public override void Close() => _innerStream.Close();
Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/dotnet/corefx/blob/master/src/Common/src/System/IO/DelegatingStream.cs

Does not implement this, I think its good to have though.

[I]
public void NotUsingSocketsHttpHandlerDoesNotCauseException()
{
AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);
Copy link
Member

Choose a reason for hiding this comment

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

Add comment this is safe to do because IntrusiveOperationCluster runs with max concurrency of 1

Copy link
Contributor

@codebrain codebrain left a comment

Choose a reason for hiding this comment

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

Reviewed via Zoom, approved with changes

@russcam russcam merged commit 90c2bf7 into master Jul 8, 2019
russcam added a commit that referenced this pull request Jul 8, 2019
This commit changes the HttpConnection to not set Content on HttpRequestMessage when there is no PostData. The check is performed inside of Request and RequestAsync to avoid creating any content instance and allocations.

Pass RequestData through to _onStreamAvailable delegates so that HttpCompression, ConnectionSettings and PostData can be accessed on the passed instance.

Fixes #3907

(cherry picked from commit 90c2bf7)
@russcam russcam deleted the fix/3907 branch July 8, 2019 02:09
russcam added a commit that referenced this pull request Jul 18, 2019
This commit changes the HttpConnection to not set Content on HttpRequestMessage when there is no PostData. The check is performed inside of Request and RequestAsync to avoid creating any content instance and allocations.

Pass RequestData through to _onStreamAvailable delegates so that HttpCompression, ConnectionSettings and PostData can be accessed on the passed instance.

Fixes #3907

(cherry picked from commit 90c2bf7)
codebrain pushed a commit that referenced this pull request Jul 19, 2019
This commit changes the HttpConnection to not set Content on HttpRequestMessage when there is no PostData. The check is performed inside of Request and RequestAsync to avoid creating any content instance and allocations.

Pass RequestData through to _onStreamAvailable delegates so that HttpCompression, ConnectionSettings and PostData can be accessed on the passed instance.

Fixes #3907

(cherry picked from commit 90c2bf7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Version 7.0.0 not working with os httphandlers
3 participants