Skip to content

Make the Patron adapter work with Patron 1.0 - #1142

Merged
bblimke merged 1 commit into
bblimke:masterfrom
julik:patron-1.0-keyword-response
Nov 18, 2026
Merged

bblimke merged 1 commit into
bblimke:masterfrom
julik:patron-1.0-keyword-response

Conversation

@julik

@julik julik commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Patron 1.0 (toland/patron#208, not released yet) moves Patron::Response.new to keyword arguments. The adapter builds every stubbed response with the six positional arguments, and since the gemspec admits any patron >= 0.4.18, a plain bundle update patron will land people on 1.0 with the old call. 1.0 ships a shim that keeps the positional form working, but it warns Patron::Response.new with positional arguments is deprecated and will be removed in Patron 1.1 once per process, and once the shim is gone in 1.1 every stubbed request raises ArgumentError.

The adapter now asks Patron::Response#initialize whether url is a required keyword and picks the form from that, so 0.x keeps getting the positional call it always got and 1.0 gets keywords with no warning. Detecting by capability rather than by version string also keeps it honest against the Patron git branch and any backport. The spec helper had the same problem one level up, passing Session#request its options as a braced Hash, which 1.0 deprecates the same way; passing them as keywords works on both lines since Ruby folds them into the trailing options = {} on 0.x.

I ran spec/acceptance/patron on patron 0.14.0 and on the 1.0 branch: 327 examples pass on each, the only failures being the ten net_connect examples that need httpstat.us, which was not answering from here. The Patron side of this is tracked in toland/patron#209.

🤖 Generated with Claude Code

Patron 1.0 moves Patron::Response.new to keyword arguments and only keeps
the positional form behind a deprecation shim that goes away in 1.1. Pick
the form from Patron::Response#initialize's parameters so that 0.x keeps
the positional call and 1.0 gets keywords without a warning. The spec
helper passed Session#request a braced options Hash, which 1.0 deprecates
the same way; keywords work on both lines.

See toland/patron#209

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@bblimke
bblimke merged commit df8fa32 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 @julik! 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