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

OPTIONS generated by CORS doesn't work correctly in local #525

Closed
jsanchezs opened this issue Sep 7, 2017 · 2 comments · Fixed by #540
Closed

OPTIONS generated by CORS doesn't work correctly in local #525

jsanchezs opened this issue Sep 7, 2017 · 2 comments · Fixed by #540
Assignees
Labels

Comments

@jsanchezs
Copy link

First of all, thank you for this awesome framework. Really easy to use, I like it a lot.

I'm developing an API that has to accept CORS and i'm having troubles with the OPTIONS methods.

The problem is easy to reproduce:
In app.py

...
@app.route('/test', methods=['POST'], cors=True)
def test_cors():
  return {'hello': 'world'}

Then, run it in local: chalice local --port=8100

When you try to do the first OPTIONS curl, everything works =)

curl -H "Origin: http://example.com" \                                                      
  -H "Access-Control-Request-Method: POST" \
  -H "Access-Control-Request-Headers: X-Requested-With" \
  -X OPTIONS --verbose \
  http://localhost:8100/test

Response:

*   Trying ::1...
* TCP_NODELAY set
* Connection failed
* connect to ::1 port 8100 failed: Connection refused
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8100 (#0)
> OPTIONS /test HTTP/1.1
> Host: localhost:8100
> User-Agent: curl/7.51.0
> Accept: */*
> Origin: http://example.com
> Access-Control-Request-Method: POST
> Access-Control-Request-Headers: X-Requested-With
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Server: BaseHTTP/0.6 Python/3.6.0
< Date: Thu, 07 Sep 2017 16:02:02 GMT
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: Authorization,Content-Type,X-Amz-Date,X-Amz-Security-Token,X-Api-Key
< Access-Control-Allow-Methods: POST,OPTIONS
<
* Curl_http_done: called premature == 0
* Closing connection 0

But the next OPTIONS curl will not end never =(

*   Trying ::1...
* TCP_NODELAY set
* Connection failed
* connect to ::1 port 8100 failed: Connection refused
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8100 (#0)
> OPTIONS /test HTTP/1.1
> Host: localhost:8100
> User-Agent: curl/7.51.0
> Accept: */*
> Origin: http://example.com
> Access-Control-Request-Method: POST
> Access-Control-Request-Headers: X-Requested-With
>
< HTTP/1.1 200 OK
< Server: BaseHTTP/0.6 Python/3.6.0
< Date: Thu, 07 Sep 2017 16:02:03 GMT
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: Authorization,Content-Type,X-Amz-Date,X-Amz-Security-Token,X-Api-Key
< Access-Control-Allow-Methods: POST,OPTIONS
* no chunk, no close, no size. Assume close to signal end

It stops in * no chunk, no close, no size. Assume close to signal end. It seems like the server only send the close signal only in the first call. If you stop the second curl and try it again, it wont stop neither.

Do you have the same problem? Can you reproduce it?

P.S.: I'm using macOS, but I hope that is not a problem to do the local development =P

@jsanchezs jsanchezs changed the title OPTIONS generated by CORS doen't work correctly in local OPTIONS generated by CORS doesn't work correctly in local Sep 8, 2017
@stealthycoin
Copy link
Contributor

stealthycoin commented Sep 8, 2017

Yep this looks like a bug to me. HTTP 1.1 defaults to not closing the connection unless the Connection: Close header is sent if there is no body.

Edit: To follow up on that, when I try this locally it hangs on the first OPTIONS request. I can't replicate getting the first one to succeed.

@stealthycoin stealthycoin self-assigned this Sep 8, 2017
@JoeStech
Copy link

I'm seeing this OPTIONS behavior when app.debug = True with Chalice 1.0.2, both locally and when deployed. Might be related, just wanted to mention it. I know I have some other issue related to my 'vendor' packages, but having a difficult time debugging because this OPTIONS behavior seems to be masking the real problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants