Search code examples
owinkatana

Content-Length: 0 with OWIN


What is the correct way to handle Content-Length when writing body content in an Owin middleware?

Currently we're using

context.Response.Write(data); // data is a string.

In most cases it works, but in some (IIS host on Win 2012 R2) the Content-Length gets a value of 0.

I thought that setting the Content-Length header, or the option to use Transfer-Encoding: chuncked was up to the host to handle, but it looks like I'm missing something.

What is the correct way to handle the Content-Length when writing body content to an OWIN Response stream?

We've also discussed the bug in a github issue.


Solution

  • It is primarily a host concern. The application may choose to set content-length if it knows exactly what it will be, but otherwise the app should let the server choose to set content-length or chunked.