Repository navigation
Keep the Content-Length of HEAD responses in the async-http adapter - #1143
Merged
bblimke merged 1 commit intoNov 20, 2026
Merged
Conversation
andrewfader
force-pushed
the
async-http-head-content-length
branch
from
November 2, 2026 09:40
d8b52bd to
f38833d
Compare
andrewfader
force-pushed
the
async-http-head-content-length
branch
2 times, most recently
from
November 17, 2026 04:25
a124743 to
92644b5
Compare
bblimke
added a commit
that referenced
this pull request
Nov 20, 2026
Keep any Protocol::HTTP::Body::Head a real response has, also one without a length, and record its length as the Content-Length. Pick the body of a HEAD stub in its own method, let the spec's make_request yield the raw response, add specs and a changelog entry.
Owner
|
Thank you @andrewfader! This is released in 3.36.0. I made a small change on top: over HTTP/2, a real response from a server that sends no |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With the async-http adapter, the response to a HEAD request loses its size, both for stubs and for real requests made while a callback is registered (VCR recording).
async-http moves
Content-Lengthoff a HEAD response's headers and onto the body, asProtocol::HTTP::Body::Head.new(length). Soresponse.body.lengthis the only place a client can read the size, and S3-style clients (aws-sdk'shead_object.content_length, for example) do exactly that.stub_request(:head, url).to_return(headers: { 'Content-Length' => '42' })serves the response with the framing headers dropped and an empty body, soresponse.bodyisnil.build_webmock_responsereads theHeadbody (which returnsnil) and replaces it withBuffered.wrap(nil), so the caller getsnilwhere it had a length. The recorded response has noContent-Lengtheither, so a cassette recorded from it replays without one.Repro against async-http 0.105.0, protocol-http 0.72.1:
Fix
WebMockApplicationserves aBody::Headcarrying the stub'sContent-Length. Stubs without one behave as before.build_webmock_responseleaves aBody::Headin place and records its length asContent-Length, which is what the server sent.Both are guarded on
Protocol::HTTP::Body::Headbeing defined, for older protocol-http.Tests
Two examples in
async_http_client_spec.rb, one stubbed and one againstWebMockServer. Both fail on master (expected: 42, got: nilandexpected: 11, got: nil) and pass with the change. The rest of the file gives the same result before and after: here, 10 examples that make real requests to external hosts fail withEOFErrorboth with and without this change.