Skip to content

Allow missing HEAD content length#69

Open
GrahamCampbell wants to merge 1 commit into
php-http:3.xfrom
GrahamCampbell:allow-missing-head-content-length-3.x
Open

Allow missing HEAD content length#69
GrahamCampbell wants to merge 1 commit into
php-http:3.xfrom
GrahamCampbell:allow-missing-head-content-length-3.x

Conversation

@GrahamCampbell

@GrahamCampbell GrahamCampbell commented Jul 2, 2026

Copy link
Copy Markdown
Contributor
Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Related tickets none
Documentation n/a
License MIT

What's in this PR?

This relaxes the request assertion for HEAD requests so a client may omit Content-Length when the server did not receive one. The assertion still checks Content-Length when a client sends it, and keeps the existing TRACE behavior.

Why?

The test suite currently makes Content-Length mandatory for HEAD requests because the default request headers include Content-Length: 0, and bodied test cases replace it with the body length. That is too strict for clients and transports that intentionally suppress HEAD request content.

If such a client kept a positive Content-Length while sending no body, the wire message would declare bytes that never arrive, which can make servers wait for the missing request body or corrupt connection framing. A missing Content-Length is valid for a HEAD request with no transmitted content, and this change only tolerates that absence; it still validates the header value when a client sends one.

Guzzle needs this while fixing guzzle/guzzle#3728 because its cURL handler must use cURL's no-body mode for HEAD requests to avoid waiting for response bodies that valid HEAD responses do not send. That mode suppresses request uploads, so Guzzle also has to omit positive request Content-Length values rather than send misleading framing headers.

Checklist

  • Updated CHANGELOG.md to describe BC breaks / deprecations | new feature | bugfix
  • Documentation pull request created (if not simply a bugfix)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant