Repository navigation
Stub get_file and streamed requests on Patron 1.1 - #1147
Merged
Merged
Conversation
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
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.
Owner
|
Thank you @sporkmonger ! This is released in 3.35.0. |
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.
Patron 1.1.0 (released 2026-11-04, Ruby 3.3+) builds
get_fileon its new streaming API, and neitherget_filenorSession#streamgoes throughSession#handle_request, which is what the adapter overrides. Patron's changelog notes this. So on Patron 1.1, a stubbedget_filemakes 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 twoget_filespecs fail. That's why every PR has failed those jobs since November 4.This also overrides the public
Session#request, for a GET with afileoption (whichget_filecalls), andSession#stream, whichget_stream,post_stream,put_streamandpatch_streamcall. Each builds the request with the publicbuild_requestand handles it likehandle_requestdoes: registering it, matching stubs, refusing it when net connect isn't allowed, and invoking callbacks.get_filewrites the stubbed body to the file and returns the stubbed response, as it did before Patron 1.1.Patron::ResponseStream: the head readers,read,readpartial,each,each_line,drain!,eof?,closeandclosed?.streamreturns aPatron::TransferStatsbuilt from it, which says whether the body was read to the end.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_filespec for an unwritable file now expectsErrno::EACCESon Patron 1.1, which is what Patron itself raises there.The new code builds its
Patron::TransferStatswith keyword arguments, which Patron 1.1 requires, so it doesn't depend on #1142. The two touch different parts ofpatron_adapter.rb.🤖 Generated with Claude Code