Skip to content

Only send Content-Length when needed.

Nick Mathewson requested to merge nickm/arti:conditional-content-length into main

According to RFC 9110:

A user agent SHOULD send Content-Length in a request when the method defines a meaning for enclosed content and it is not sending Transfer-Encoding. For example, a user agent normally sends Content-Length in a POST request even when the value is 0 (indicating empty content). A user agent SHOULD NOT send a Content-Length header field when the request message does not contain content and the method semantics do not anticipate such data.

Part of #1024 (closed).

@gabi-250 , I'm assigning this to you for review, since you wrote 7ae30d9c ("Always set the Content-Length header"). This is not a pure revert: Originally, we would set content-length when the body was non-empty. With your commit, we set content-length unconditionally. After this commit, we set content-length when the body is non-empty OR the method is POST.

(Do you remember what tests you were doing when you said // TODO SPEC dir-spec says Content-Length is optional but empirically it's required? ?)

Merge request reports

Loading