It seems that the framework never sets the content-length header so ASP sends as chunked because it doesn't find the content-length header.
I hacked it by setting content length in the Controller using a specific encoding (ASCII) and then made sure to stream the string in the MediaFormatter with the same encoding.
Not the perfect solution but neither is the client
Thanks Kiran, do you have any advice on possible workarounds for the bug without having to take this fix (and therefore quite a lot of other change). For example, is there an opportunity to de-chunk before sending to the client or force it to treat it as
an HTTP 1.0 request?
I tried getting the initial check-in of the source code and building it but the Nuget packages it refers to (e.g. DotNetOpenAuth.OpenId.Core at version 4.0.0.0-beta2) don't seem to be available anymore. Also this approach won't have the go-live license guarantee.
As a side-note we're also finding it very hard to repro despite issuing the same request and same headers from other machines it does not cause the chunking. On other machines and particularly a device that cannot
cope with chunking, we always get chunking (and we really need this device to work).
<- turns out some peopele had "Decode" option at the top of fiddler enabled and some didn't, response is always chunked.
Fixed this in similar way to sthiakos by reading the content into a memory stream in our custom MediaTypeFormatter and then setting the Content-Length header.
I had to use System.Web.HttpContext.Current.Response.Headers for this because the other header collections in the parameters for the MediaTypeFormatter didn't seem to affect the response.
sthiakos
Member
4 Points
4 Posts
Prevent/Omit Transfer-Encoding: chunked
Mar 30, 2012 01:26 AM|LINK
Hello Forum,
How can I prevent/omit/remove chunked transfer-encoding? Would removing the header stop the framework from sending the chunked format (bSome Text0)
I'm using the following (simplified) Custom Media Formatter - is that forcing chunked?
I'd like to prevent this for all reponses from my site.
Also can you code-review the snippet and let us know if that the expected way to implement?
Thanks,
Steve
protected override Task OnWriteToStreamAsync(Type type, object value, Stream stream, HttpContentHeaders contentHeaders, FormatterContext formatterContext, TransportContext transportContext) { return Task.Factory.StartNew(() => { string response = "Some Text"; StreamWriter streamWriter = new StreamWriter(stream); streamWriter.Write(response); streamWriter.Flush(); }); }sthiakos
Member
4 Points
4 Posts
Re: Prevent/Omit Transfer-Encoding: chunked
Mar 30, 2012 07:49 PM|LINK
Figured it out
It seems that the framework never sets the content-length header so ASP sends as chunked because it doesn't find the content-length header.
I hacked it by setting content length in the Controller using a specific encoding (ASCII) and then made sure to stream the string in the MediaFormatter with the same encoding.
Not the perfect solution but neither is the client
No worries for the code review.
Steve
LittleClive
Member
91 Points
65 Posts
Re: Prevent/Omit Transfer-Encoding: chunked
May 24, 2012 02:06 PM|LINK
There was also this bug which appears to have been fixed post beta:
http://aspnetwebstack.codeplex.com/SourceControl/changeset/changes/06f52b894414#src%2fSystem.Web.Http.WebHost%2fHttpControllerHandler.cs
I'm trying to work out how to take this fix without upgrading everything to a potentially unstable build now (hints appreciated).
Kiran Challa
Participant
1442 Points
281 Posts
Microsoft
Re: Prevent/Omit Transfer-Encoding: chunked
May 24, 2012 04:25 PM|LINK
yes, thats right...it has been fixed currently.
[Updated] For more details on how chunking happens for different contents currently, you can go here.
Kiran Challa
LittleClive
Member
91 Points
65 Posts
Re: Prevent/Omit Transfer-Encoding: chunked
May 25, 2012 08:46 AM|LINK
Thanks Kiran, do you have any advice on possible workarounds for the bug without having to take this fix (and therefore quite a lot of other change). For example, is there an opportunity to de-chunk before sending to the client or force it to treat it as an HTTP 1.0 request?
I tried getting the initial check-in of the source code and building it but the Nuget packages it refers to (e.g. DotNetOpenAuth.OpenId.Core at version 4.0.0.0-beta2) don't seem to be available anymore. Also this approach won't have the go-live license guarantee.
As a side-note we're also finding it very hard to repro despite issuing the same request and same headers from other machines it does not cause the chunking. On other machines and particularly a device that cannot cope with chunking, we always get chunking (and we really need this device to work). <- turns out some peopele had "Decode" option at the top of fiddler enabled and some didn't, response is always chunked.
LittleClive
Member
91 Points
65 Posts
Re: Prevent/Omit Transfer-Encoding: chunked
May 28, 2012 10:14 AM|LINK
Fixed this in similar way to sthiakos by reading the content into a memory stream in our custom MediaTypeFormatter and then setting the Content-Length header.
I had to use System.Web.HttpContext.Current.Response.Headers for this because the other header collections in the parameters for the MediaTypeFormatter didn't seem to affect the response.