HTTP POST: content-length header required?
Asked Answered
T

1

44

I'm currently trying to optimize http-based data transfer between several applications. Our current approach, downloading first and then creating the post-request, obviously add extra IO/memory load and latencies, which I'd like to circumvent.

The core question of all:

Is it required to send a "Content-Length" header in HTTP POST requests? IIRC, HTTP 2616 declares that it's optional, but I'm not sure how applications actually behave at this point.

Talkative answered 7/2, 2013 at 18:52 Comment(1)
R
33

Depends what you mean by optional. If you mean that you can just omit the header anytime you like then no, it is not optional. The HTTP spec has very specific rules when to use that header. There are different ways of sending the data if you don't know the length. Chunked encoding for example.

4.4 Message Length

Request answered 7/2, 2013 at 19:44 Comment(2)
In brief, for POST requests one of content-length or transfer-encoding:chunked headers should be present.Meilhac
The documentation for "Content-Length" is now here: rfc-editor.org/rfc/rfc9110.html#name-content-lengthGlia

© 2022 - 2024 — McMap. All rights reserved.