aspnet / HttpAbstractions

[Archived] HTTP abstractions such as HttpRequest, HttpResponse, and HttpContext, as well as common web utilities. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
382 stars 194 forks source link

Fix FileBufferingReadStream not working with StreamContent #1032

Closed cnblogs-dudu closed 6 years ago

cnblogs-dudu commented 6 years ago

Address dotnet/corefx#31866

Before FileBufferingReadStream is first read, it's length is not properly set. Before StreamContent is read, it's inner stream length is used to compute ContentLength. When they get together in HttpClient, an http request with misleading Content-Length: 0 is produced.

This PR introduces _innerLength to return the length of inner stream before FileBufferingReadStream is first read.

Tratcher commented 6 years ago

This is at best a partial fix, it still wouldn't work for chunked requests. The end to end still needs more thought.

Tratcher commented 6 years ago

I don't think this is the right place to fix your problem. It only addresses the Content-Length scenario and it makes Content-Length and Chunked behave differently for everybody else. I expect you'd be better of creating a custom HttpContent object that managed this for you.