Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS requests fail with a 405 method not allow for OPTIONS #865

Closed
v9n opened this issue Apr 15, 2015 · 15 comments · Fixed by #3885
Closed

CORS requests fail with a 405 method not allow for OPTIONS #865

v9n opened this issue Apr 15, 2015 · 15 comments · Fixed by #3885
Labels
theme/api Relating to the HTTP API interface type/enhancement Proposed improvement or new feature
Milestone

Comments

@v9n
Copy link

v9n commented Apr 15, 2015

Hi,

I tried to setup CORS headers:

{
  "http_api_response_headers": {
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Methods": "POST, GET, OPTIONS, DELETE, PUT"
  }
}

I verified that those headers are return during a XHR request. However, when I tried to do PUT, browser send an OPTIONS request first (http://stackoverflow.com/questions/8153832/xmlhttprequest-changes-post-to-option) and consul return a 405 method not allow.

My request looks like this:

curl 'http://192.168.111.30:8500/v1/kv/lb/extra_hosts/opi' -X OPTIONS -H 'Host: 192.168.111.30:8500' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:39.0) Gecko/20100101 Firefox/39.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'DNT: 1' -H 'Origin: http://local.dev:8101' -H 'Access-Control-Request-Method: PUT' -H 'Connection: keep-alive'

and response

screen shot 2015-04-15 at 9 43 06 am

So I think the issue comes from consul itself when denied OPTIONS method?

@pearkes
Copy link
Contributor

pearkes commented Apr 15, 2015

I think to properly run cross domain with non POST/GET methods, we do need to respond to the OPTIONS preflight request. POST and GET don't send a preflight, and to my knowledge there's no way to skip preflight with headers.

So, we'll need to respond to OPTIONS, basically.

@h2non
Copy link

h2non commented May 3, 2015

It could be great if the CORS headers could be inferred and settled automatically to avoid issues in browsers. Following the W3C spec this could be done easily based on the existent HTTP request headers.

Probably adding a new Consul config field to enable it would be fine, or alternatively as sort of plugin/addon. The config field could be:

enableFullCORS: true

@teaforthecat
Copy link

I'm running into this too. Is there any reason we wouldn't want "enableFullCORS: true" to be default ?

@h2non
Copy link

h2non commented Jun 23, 2015

IMO Consul should implement CORS support by default inferring it based on the request HTTP, unless it's explicitly defined that you don't want enable it.

@DarrenN
Copy link

DarrenN commented Jul 8, 2015

This is becoming quite a problem when developing against Consul Agent running locally. The browser app I'm working on cannot make PUTs due to blocked OPTIONS.

@marconi
Copy link

marconi commented Mar 8, 2016

same here, it should be able to handle OPTIONS request.

@marconi
Copy link

marconi commented Mar 8, 2016

UPDATE: I opened a PR #1807, note this is only for kv.

@langston-barrett
Copy link
Contributor

langston-barrett commented Apr 16, 2016

I am also attempting to develop browser application to interact with the Consul HTTP API, and am blocked by this issue. It also effects DELETE requests. Here's what it looks like on the raw HTTP header level:

$ curl -v -X OPTIONS http://localhost:8500/v1/kv/
*   Trying ::1...
* Connected to localhost (::1) port 8500 (#0)
> OPTIONS /v1/kv/ HTTP/1.1
> Host: localhost:8500
> User-Agent: curl/7.48.0
> Accept: */*
> 
< HTTP/1.1 405 Method Not Allowed
< Access-Control-Allow-Origin: *
< Date: Sat, 16 Apr 2016 07:18:42 GMT
< Content-Length: 0
< Content-Type: text/plain; charset=utf-8
< 
* Connection #0 to host localhost left intact

@gmagniez
Copy link

Hi,
Same issue with 'v1/event/fire' api endpoint

@mosheavni
Copy link

No solution yet? I can't use PUT to update k/v on a web UI I'm building.
Help?

@Yanovskiy
Copy link

Any update?

@slackpad
Copy link
Contributor

slackpad commented May 2, 2017

Now that we support https://www.consul.io/docs/agent/options.html#http_api_response_headers, can we just add generic support for OPTIONS requests and make things work?

@slackpad slackpad added the type/enhancement Proposed improvement or new feature label May 2, 2017
@slackpad slackpad added the theme/api Relating to the HTTP API interface label May 25, 2017
@Cosmo439
Copy link

Any update on this? It's blocking me on developing an app against the API.

@bersalazar
Copy link

Running into this same issue.

@slackpad slackpad added this to the Unplanned milestone Feb 5, 2018
@eddsteel
Copy link
Contributor

I'm running my fork and successfully using CORS PUTs to kv endpoints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/api Relating to the HTTP API interface type/enhancement Proposed improvement or new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.