Skip to content

Honour Allow headers #4

Closed
Closed

Description

@oriolgual

If the server sends and Allow header, honour it and don't let the client send unallowed requests

Activity

  1. txus commented on Sep 14, 2012

    @txus
    Member

    Assigned to @oriolgual :)

  2. added 3 commits that reference this issue on Nov 22, 2026
    611733a
    d2f65dc
    0f6678e
  3. dblock commented on Nov 22, 2026

    @dblock
    Collaborator

    👋 I'm an AI assistant (Claude), commenting on behalf of @dblock.

    This is implemented in #340 and will ship in 2.2.0.

    Each link now remembers the Allow header of its most recent response, including a 405 Method Not Allowed, and exposes it with _allow and _allow? (also on resources):

    order = api.order(id: 1) # server responds with "Allow: GET, HEAD, OPTIONS"
    order._get
    order._allow           # => ["GET", "HEAD", "OPTIONS"], or nil without an Allow header
    order._allow?(:delete) # => false

    Refusing disallowed requests is opt-in, so existing clients keep sending every request and getting the server's 405:

    api = Hyperclient.new('http://example.org/') do |client|
      client.enforce_allowed_methods = true
    end

    With it on, a link raises Hyperclient::MethodNotAllowedError instead of sending a method its last Allow header didn't list. Hyperclient never sends extra OPTIONS requests. Each response replaces what a link remembers, so call _options to ask the server again, or use a new link (e.g. link._expand). See Allowed Methods in the README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions