Skip to content

Headers set in before not respected for auto generated method OPTIONS #406

Closed
@jbarreneche

Description

@jbarreneche

This is useful for CORS (see issue #170)

Example:

require 'grape'

class Test < Grape::API
  before do
    header "Access-Control-Allow-Origin", "*"
  end

  post "/" do
    "Hello"
  end
end

run Test

The header for the method POST works correctly

$ curl -i -X POST  --data "" localhost:9292/   
HTTP/1.1 201 Created 
Access-Control-Allow-Origin: *
Content-Type: text/plain
Content-Length: 5
Server: WEBrick/1.3.1 (Ruby/2.0.0/2013-02-24)
Date: Wed, 15 May 2013 13:53:28 GMT
Connection: Keep-Alive

Hello

but the header for the method OPTION doesn't respect the headers set in the before block.

$ curl -i -X OPTIONS  --data "" localhost:9292/
HTTP/1.1 204 No Content 
Allow: OPTIONS, POST
Server: WEBrick/1.3.1 (Ruby/2.0.0/2013-02-24)
Date: Wed, 15 May 2013 13:54:45 GMT
Connection: Keep-Alive

The culprit seems to be the way this method is added to the route set.

I can try to fix it, but I'd like some pointers on the best way to build that enpoint so it includes the before callbacks.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions