Closed
Description
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.