Skip to content
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

Multipart test failing in .NET Core #179

Closed
tmenier opened this issue May 8, 2017 · 4 comments
Closed

Multipart test failing in .NET Core #179

tmenier opened this issue May 8, 2017 · 4 comments
Assignees

Comments

@tmenier
Copy link
Owner

tmenier commented May 8, 2017

RealHttpTests.can_post_multipart recently started failing in .NET Core. Since no code had changed related to this, I figured something must be broken with httpbin. But why only with .NET Core? I opened up Fiddler and had a look at the requests. The difference is immediately clear from the request headers:

Full framework:

Content-Type: multipart/form-data; boundary="3f77156c-5238-4535-a738-f1811a21ba3a"
Host: httpbin.org
Content-Length: 735
Expect: 100-continue
Connection: Keep-Alive

.NET Core:

Content-Type: multipart/form-data; boundary="4a27011b-63be-4176-a8d6-97f94166adf6"
Host: httpbin.org
Connection: Keep-Alive
Transfer-Encoding: chunked
Accept-Encoding: gzip, deflate

Aha! The .NET Core version is doing chunked encoding, the handling of which is indeed a recent regression bug with httpbin. I'm not sure why the 2 versions of HttpClient behave differently in this regard, but I figured turning off chunked encoding just for this test should at least work around the httpbin bug. But I haven't been able to figure out how to do that. Even if I set HttpRequestMessage.Headers.TransferEncodingChunked to false immediately before SendAsync of the inner handler is called, it doesn't stick. Something deep down in HttpClientHandler is apparently deciding to chunk the request. You can see this by setting a breakpoint anywhere after the request is sent and observing that TransferEncodingChunked has been set to true.

@kroniak I know you're working on changes for the next major version where we'll be targeting 1.1 and above only. Wondering if you can verify whether this chunking behavior still exists in 1.1, or if you have any other suggestions on what to do here?

@kroniak
Copy link
Collaborator

kroniak commented May 16, 2017

Work on #176 stops because nuget does not add PCL parget to final package. I am waiting. And I will see to this issue.

@kroniak
Copy link
Collaborator

kroniak commented Jun 5, 2017

I will continue working on issue.

tmenier added a commit that referenced this issue Jun 5, 2017
@tmenier
Copy link
Owner Author

tmenier commented Jun 5, 2017

I think I found where TransferEncodingChunked is turned on:

https://github.com/dotnet/corefx/blob/1f77137ecb1958fe961f1d3b324ec8e2bbcd73c5/src/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpHandler.cs#L588-L594

From there I was able to disable chunking and fix the test by setting the content-length header explicitly.

@kroniak Don't worry about this one - I don't think .NET Core is doing anything wrong here, and in fact the behavior is probably a good enhancement, so I doubt they'll revert it in a newer version. The real problem is a bug in library that httpbin depends on. Once that's fixed, I'll undo the above commit. It's probably good for a chunked upload to get tested anyway. I think they're just waiting on this PR to get merged.

@tmenier tmenier assigned tmenier and unassigned kroniak Jun 5, 2017
@tmenier
Copy link
Owner Author

tmenier commented Jun 20, 2018

Appears to be working on httpbin now without my hack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants