Could someone tell me about that Content-Length or Transfer-Encoding: \"Chunked\" is a must for Http request ? I\'m using c++ to write a http sever.
The http respond
If you don't specify a Transfer-Encoding
or Content-Length
then the request (or response) is implicitly a variable length request/response and the only way to signal the end of the body is to shutdown the connection (and conversely detect the shutdown/eof in the receiver).
This means that this kind of request/response is also implicitly Connection: close
If you're implementing HTTP1.1 then you must support all three transfer methods.
When I wrote my HTTP server I abstracted the concept of a "request stream" from the concept of a "connection stream". The "request stream" is polymorphic and supports the concept of reading to "EOF". There's no reason you couldn't also have a method on there to "read_chunk". In the case of a non-chunked request, this could simply read until EOF.
This allowed me to implement simultaneous execution of multiple requests on the same connection (but there is some jiggery-pokery to ensure that the responses go back in the correct order!)