The Problem
I am serving a resource of unknown length via Node.JS. Because of this, the Content-Length
header cannot be set. For HTTP 1.1, it is required that chunked encoding is used for resources of this nature. Node.JS knows this and sends my data with chunked transfer encoding all on its own, with the following headers:
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Connection: close
...
This is all fine and good for well-behaved clients. However, I have some not-so-well behaved clients (namely Android 2.2 and earlier) that I must support. These clients do not support chunked transfer encoding properly.
Fix Attempt #1
My initial thought was set the encoding to none
like so:
response.writeHead(200, {'Transfer-Encoding': 'none'});
This disables Node.JS's automatic chunked encoding and maintains compatibility with most clients. However, now I have broken Android 2.3+ clients, as they simply cough and choke when they see such a bogus transfer encoding header.
Fix Attempt #2 (where I need help)
When I make requests with HTTP/1.0
, the server properly returns the response without chunked encoding:
HTTP/1.1 200 OK
Connection: close
...
This solves my problem, and allows me to serve a stream that works for all of my troublesome clients. I don't have to send a bogus header for Transfer-Encoding
, and I still don't have to specify how long the content is.
How can I force Node.JS's HTTP server to always serve in HTTP/1.0 mode?