Skip to content

Stub get_file and streamed requests on Patron 1.1 - #1147

Merged
bblimke merged 1 commit into
bblimke:masterfrom
sporkmonger:patron-stream-stubs
Nov 18, 2026
Merged

bblimke merged 1 commit into
bblimke:masterfrom
sporkmonger:patron-stream-stubs

Conversation

@sporkmonger

Copy link
Copy Markdown
Contributor

Patron 1.1.0 (released 2026-11-04, Ruby 3.3+) builds get_file on its new streaming API, and neither get_file nor Session#stream goes through Session#handle_request, which is what the adapter overrides. Patron's changelog notes this. So on Patron 1.1, a stubbed get_file makes a real request and writes the real response to the file, and streamed requests aren't stubbed or blocked at all. CI picks up Patron 1.1 on Ruby 3.3, 3.4 and 4.0, where the two get_file specs fail. That's why every PR has failed those jobs since November 4.

This also overrides the public Session#request, for a GET with a file option (which get_file calls), and Session#stream, which get_stream, post_stream, put_stream and patch_stream call. Each builds the request with the public build_request and handles it like handle_request does: registering it, matching stubs, refusing it when net connect isn't allowed, and invoking callbacks.

  • A stubbed get_file writes the stubbed body to the file and returns the stubbed response, as it did before Patron 1.1.
  • A stubbed stream yields a stand-in with the public API of Patron::ResponseStream: the head readers, read, readpartial, each, each_line, drain!, eof?, close and closed?. stream returns a Patron::TransferStats built from it, which says whether the body was read to the end.
  • On older Patron versions, which don't have Session#stream, nothing changes.

After-request callbacks for a real streamed request get the status and headers but no body, since the body goes to the caller's block.

The get_file spec for an unwritable file now expects Errno::EACCES on Patron 1.1, which is what Patron itself raises there.

The new code builds its Patron::TransferStats with keyword arguments, which Patron 1.1 requires, so it doesn't depend on #1142. The two touch different parts of patron_adapter.rb.

🤖 Generated with Claude Code

Patron 1.1 builds get_file on its new streaming API, and neither goes
through Session#handle_request, so stubs were bypassed and real
requests were made. The adapter now also overrides the public
Session#request (for GET with a file) and Session#stream, which the
*_stream helpers call. A stubbed stream yields a stand-in with the
public reading API of Patron::ResponseStream and returns a
Patron::TransferStats.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bblimke
bblimke merged commit 975d939 into bblimke:master Nov 18, 2026
8 checks passed
bblimke added a commit that referenced this pull request Nov 18, 2026
#1147 overrode Session#request to catch a GET with a file, which meant
copying Patron's check for when it downloads and its handling of the old
positional options Hash. Patron's deprecation warning for that Hash then
pointed at the adapter rather than the caller, and two positional Hashes
were accepted where Patron raises ArgumentError. Override the private
Session#download instead, which Patron 1.1 calls with the request
already built.

handle_request, download and stream now share one method that records
the request, finds the stub and refuses the request when real
connections are not allowed, so the three cannot drift apart.

Callbacks for a streamed request now run before the block, for stubbed
and real requests alike, as the Net::HTTP adapter does. Previously they
were skipped when the block exited early with break, return or an
exception, which Patron expects for event streams.

Build the header data in one place for the response and the transfer
stats, and decide once at load time whether Patron::Response.new takes
keyword arguments (#1142).

Add specs for an unstubbed and a real get_file, header and query
matching on a streamed request, and blocks that break or raise.
Document both PRs in the CHANGELOG.
@bblimke

bblimke commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thank you @sporkmonger ! This is released in 3.35.0.

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.

2 participants