pjfanning opened a new pull request, #1244:
URL: https://github.com/apache/pekko-http/pull/1244

   cherry pick dd0a4a334bdb6a1908146a53eaf9064a1d181a22 (#1237)
   
   Motivation:
   PR #962 corrected Content-Length rendering for 205 and CONNECT, but it also 
made HEAD responses drop the header unconditionally. RFC 9110 section 8.6 
allows a server to send Content-Length in a HEAD response, and RFC 9112 section 
6.3 rule 1 exempts HEAD responses from body framing, so the header is metadata 
there and cannot desync a connection. Suppressing it breaks the common case of 
using HEAD to learn the size of a resource without fetching it, and it is 
asymmetric: our own client parser honours a HEAD Content-Length, and the HTTP/2 
renderer never consulted contentLengthAllowed at all.
   
   Modification:
   Restore the pre-1.4 predicate for HEAD (contentLengthAllowedForHead now 
defers to StatusCode.allowsEntity) and add the length-based policy at render 
time: a HEAD response renders Content-Length only when the entity declares a 
length greater than zero. A zero length nearly always means the application had 
no body to hand over rather than that the resource is empty, and the client 
parser already only honours a HEAD Content-Length when it is greater than zero. 
Chunked and CloseDelimited entities have no known length and are unchanged. 
205, 204, 304 and CONNECT behaviour from #962 is untouched.
   
   Result:
   A HEAD response completed with HttpEntity.Strict or 
HttpEntity.Default(contentType, length, Source.empty) renders the declared 
Content-Length again, while an empty entity renders none.
   
   Tests:
   - sbt "http-core / Test / testOnly 
org.apache.pekko.http.impl.engine.rendering.ResponseRendererSpec 
org.apache.pekko.http.impl.engine.server.HttpServerSpec 
org.apache.pekko.http.scaladsl.model.HttpMethodsSpec" - 110 passed
   - sbt "http-core / Test / testOnly 
org.apache.pekko.http.impl.engine.client.HostConnectionPoolSpec" - 66 passed
   - sbt +mimaReportBinaryIssues - success
   - scalafmt --mode diff-ref=upstream/main - clean
   - git diff --check - clean
   - sbt "http-core / test" and sbt "docs / paradox" - not run to completion 
locally, left to CI
   
   References:
   Fixes #1236, Refs #962


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to