Repository navigation
Honor the Allow header - #340
Merged
Merged
Conversation
dblock
force-pushed
the
dblock/allow-header
branch
from
November 22, 2026 14:02
27500c3 to
da94679
Compare
dblock
force-pushed
the
dblock/allow-header
branch
2 times, most recently
from
November 22, 2026 14:40
611733a to
d2f65dc
Compare
Remember the Allow header of a link's most recent response, including 405 responses, and expose it with Link#_allow, Link#_allow?, Resource#_allow and Resource#_allow?. Add an opt-in EntryPoint#enforce_allowed_methods setting that raises Hyperclient::MethodNotAllowedError before sending a method the link's most recent Allow header doesn't list. It defaults to off, so existing clients keep sending every request and receiving the server's 405. Closes codegram#4. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011Gr21htyJfr8XZGHBcPwkW
dblock
force-pushed
the
dblock/allow-header
branch
from
November 22, 2026 14:45
d2f65dc to
0f6678e
Compare
Closed
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.
Closes #4.
Design
A
Linkusually hasn't fetched its target before_post/_delete, so the client can only honorAllowwhen it has already seen a response for that same link. This PR uses exactly that knowledge and never sends implicit extra requests.Each
Linkremembers theAllowheader of its most recent response, from any method, including a405 Method Not Allowedresponse (RFC 9110 requires it to carryAllow). With the defaultRaiseErrormiddleware the header is read from theFaraday::ClientErrorresponse before re-raising.Read-only accessors, always available:
Link#_allow/Link#_allow?(method)andResource#_allow/Resource#_allow?(method)(the latter from the response that created the resource)._allowreturnsnilwhen noAllowheader was seen and_allow?then returnstrue.Enforcement is opt-in with
EntryPoint#enforce_allowed_methods(defaultfalse):When enabled, if the remembered list excludes the method, the link raises
Hyperclient::MethodNotAllowedError(withhttp_method,urlandallowed) instead of contacting the server. Each response replaces what the link knows, so a later response withoutAllowlifts the restriction._optionsis never blocked, so callers can always rediscover the allowed methods. New link objects (e.g. from_expand,_query, or a resource's_links) start without restrictions.Parsing is case-insensitive, splits on commas, strips whitespace, ignores empty entries and duplicates. An empty
Allowheader means no methods are allowed.HEADis not implied byGET.Why opt-in: enforcing by default would change the error existing code sees for a disallowed request from the server's 405 (
Faraday::ClientError) toHyperclient::MethodNotAllowedError, in a minor release.Allowis also a snapshot that can change with authentication or resource state, and enforcement only saves one request the server would refuse anyway. With the default, every request is sent exactly as before.Not covered:
Resource#_postetc. delegate to the resource's self link, which is a separateLinkobject, so they are not restricted by the response that created the resource;Resource#_allow?is available for that check. I kept enforcement on the link that actually made the request, since the self link's URL may differ from the requested one.Validation
bundle exec rakepasses locally on Ruby 4.0.9: 195 runs, 32 Spinach steps, RuboCop clean.test/hyperclient/link_test.rb,test/hyperclient/resource_test.rbandtest/hyperclient/entry_point_test.rbcover parsing edge cases and the accessors; by default, a disallowed method is still sent and a 405 is repeated (these fail if enforcement is unconditional); withenforce_allowed_methods, allowed and disallowed methods, the error's attributes and message, emptyAllow, OPTIONS exemption, HEAD not implied by GET, 405 responses with and withoutRaiseError(asserting the second request is never sent), most-recent-response replacement and per-link scope; and the setting's default and setter.enforce_allowed_methods = true) against a Faraday test adapter and confirmed the documented output.🤖 Generated with Claude Code
https://claude.ai/code/session_011Gr21htyJfr8XZGHBcPwkW