Il 24/11/2017 16:43, goldsimon ha scritto:
You're
right in that it doesn't work. The browser has no way to know the
body size.
The downside of not sending conten length is that the server will
have to close the connection. Reopening it might take longer than
just sending zero bytes to create the correct content size...
Why the server should close the connection when the Content Length
header is not send? I tried and it seems it works well:
Server is 192.168.1.201, client is 151.45.118.38. The request is GET
log.cgi?first=0&num=8 (packet n. 57). The answer is at the
selected packet (n. 74). As you can see, the server doesn't send
Content-Length header (I made some modifications on httpd.c) and the
body (JSON data) is included in the same TCP session.
Of course the client couldn't know the length of data in advance,
but this isn't a problem for me. They aren't too big, the only issue
is that they aren't available when the headers are generated.
Indeed, get_http_headers() function is called from http_init_file(),
IMHO too early. A small improvement could be to call
get_http_headers() when at least the first block of data is
available. In my case, I have only a single block of data, so I
could send the correct Content-Length header. I will add this
request on savannah.
Anyway, at least for the moment, the solution to avoid sending
Content-Length is ok for me.
|