Last post May 28, 2012 06:14 AM by LittleClive
Mar 29, 2012 09:26 PM|sthiakos|LINK
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?
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);
HTTP/1.1 200 OK
Date: Fri, 30 Mar 2012 01:08:43 GMT
Mar 30, 2012 03:49 PM|sthiakos|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.
May 24, 2012 10:06 AM|LittleClive|LINK
There was also this bug which appears to have been fixed post beta:
I'm trying to work out how to take this fix without upgrading everything to a potentially unstable build now (hints appreciated).
May 24, 2012 12:25 PM|Kiran Challa|LINK
yes, thats right...it has been fixed currently.
[Updated] For more details on how chunking happens for different contents currently, you can go
May 25, 2012 04:46 AM|LittleClive|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 220.127.116.11-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.
May 28, 2012 06:14 AM|LittleClive|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.