When setting response.Headers.TransferEncodingChunked, the response doesn't get chunked, and a client (Fiddler) will fail trying to read the response.
Repro 1:
public HttpResponseMessage Get()
{
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
response.Headers.TransferEncodingChunked = true;
response.RequestMessage = Request;
return response;
}
Repro 2:
public HttpResponseMessage Get()
{
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new LazyContent();
response.Headers.TransferEncodingChunked = true;
response.RequestMessage = Request;
return response;
}
public class LazyContent : HttpContent
{
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
stream.WriteByte(0);
return Task.FromResult<object>(null);
}
protected override bool TryComputeLength(out long length)
{
length = 0;
return false;
}
}
Comments: The problem actually repros regardless of the buffering policy. I've tried both of the following options: config.Services.Replace(typeof(IHostBufferPolicySelector), new AlwaysBufferPolicySelector()); config.Services.Replace(typeof(IHostBufferPolicySelector), new NeverBufferPolicySelector()); private class NeverBufferPolicySelector : IHostBufferPolicySelector { public bool UseBufferedInputStream(object hostContext) { return false; } public bool UseBufferedOutputStream(System.Net.Http.HttpResponseMessage response) { return false; } } private class AlwaysBufferPolicySelector : IHostBufferPolicySelector { public bool UseBufferedInputStream(object hostContext) { return false; } public bool UseBufferedOutputStream(System.Net.Http.HttpResponseMessage response) { return false; } } Without that the following header set, the buffer policy selector does control chunking: response.Headers.TransferEncodingChunked = true; But with that header set, the response is not handled correctly with either of the buffer policies above.
Repro 1:
public HttpResponseMessage Get()
{
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
response.Headers.TransferEncodingChunked = true;
response.RequestMessage = Request;
return response;
}
Repro 2:
public HttpResponseMessage Get()
{
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new LazyContent();
response.Headers.TransferEncodingChunked = true;
response.RequestMessage = Request;
return response;
}
public class LazyContent : HttpContent
{
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
stream.WriteByte(0);
return Task.FromResult<object>(null);
}
protected override bool TryComputeLength(out long length)
{
length = 0;
return false;
}
}
Comments: The problem actually repros regardless of the buffering policy. I've tried both of the following options: config.Services.Replace(typeof(IHostBufferPolicySelector), new AlwaysBufferPolicySelector()); config.Services.Replace(typeof(IHostBufferPolicySelector), new NeverBufferPolicySelector()); private class NeverBufferPolicySelector : IHostBufferPolicySelector { public bool UseBufferedInputStream(object hostContext) { return false; } public bool UseBufferedOutputStream(System.Net.Http.HttpResponseMessage response) { return false; } } private class AlwaysBufferPolicySelector : IHostBufferPolicySelector { public bool UseBufferedInputStream(object hostContext) { return false; } public bool UseBufferedOutputStream(System.Net.Http.HttpResponseMessage response) { return false; } } Without that the following header set, the buffer policy selector does control chunking: response.Headers.TransferEncodingChunked = true; But with that header set, the response is not handled correctly with either of the buffer policies above.