Skip to content

curl request snippet for a HEAD request hangs waiting for a response body - #1087

Merged
wilkinsona merged 1 commit into
spring-projects:4.0.xfrom
chuuminggg:curl-head-request
Nov 13, 2026
Merged

wilkinsona merged 1 commit into
spring-projects:4.0.xfrom
chuuminggg:curl-head-request

Conversation

@chuuminggg

Copy link
Copy Markdown
Contributor

For a HEAD request, the curl request snippet uses -X HEAD:

$ curl 'http://localhost:8080/items' -i -X HEAD

-X only changes the method name in the request. It doesn't change how curl handles the response, so curl still waits for the number of bytes in the Content-Length header. A response to a HEAD request has no body, so the documented command hangs until it times out. curl's documentation for -X says the same: "if you want to make a proper HEAD request, using -X HEAD does not suffice. You need to use the --head option." (-I is the short form of --head.)

I checked this with curl 8.16.0 against a local server that answers HEAD with Content-Length: 13 and no body:

Command Result
curl '…/foo' -i -u 'user:secret' -X HEAD -H 'Accept: application/json' --max-time 5 Headers are printed, then curl: (28) Operation timed out after 5002 milliseconds with 0 out of 13 bytes received
curl '…/foo' -I -u 'user:secret' -H 'Accept: application/json' --max-time 5 Finishes in 0.1 s with exit code 0

The server received the same request from both commands: method HEAD, the Authorization header, and the Accept header.

This PR makes the snippet use -I instead of -i -X HEAD for a HEAD request. -I also includes the response headers in the output, so it replaces -i as well. The snippets for other methods are unchanged. The HTTPie snippet doesn't need a change, as http HEAD … already makes a proper HEAD request.

@wilkinsona wilkinsona added type: bug A bug and removed status: waiting-for-triage Untriaged issue labels Nov 9, 2026
@wilkinsona wilkinsona added this to the 4.0.x milestone Nov 9, 2026
Previously, the curl request snippet for a HEAD request used -X HEAD.
This only changes the method name, so curl still waited for a response
body that is never sent and the documented command hung until it timed
out. -I is now used instead, which also includes the response headers
in the output.

Signed-off-by: chuuminggg <rorrxr@naver.com>

See spring-projectsgh-1087
@wilkinsona wilkinsona modified the milestones: 4.0.x, 4.0.3 Nov 13, 2026
@wilkinsona
wilkinsona merged commit 3f8f067 into spring-projects:4.0.x Nov 13, 2026
1 check passed
@wilkinsona

Copy link
Copy Markdown
Member

Thanks again, @chuuminggg.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants