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

Missing CORS headers in response with latest sanic 22.9.0 #64

Closed
philipnbbc opened this issue Oct 3, 2022 · 4 comments
Closed

Missing CORS headers in response with latest sanic 22.9.0 #64

philipnbbc opened this issue Oct 3, 2022 · 4 comments

Comments

@philipnbbc
Copy link

It appears that sanic_cors (2.1.0) with the latest version of sanic (22.9.0) fails to add CORS headers when combined with other response middleware .

The test code provided below demonstrates the issue.

Run with TEST_WITH_OTHER_MIDDLEWARE = False and curl -i http://127.0.0.1:8000 returns Access-Control-Allow-Origin: *. Run it with TEST_WITH_OTHER_MIDDLEWARE = True and that header is not returned.

Installing sanic<22.9 results in the CORS header being returned in both cases.

from sanic import Sanic
from sanic.response import json
from sanic_cors import CORS

TEST_WITH_OTHER_MIDDLEWARE = True

app = Sanic("my-hello-world-app")

async def other_response_middleware(request, response):
    return None

@app.route('/')
async def test(request):
    return json({'hello': 'world'})

CORS(app)
if TEST_WITH_OTHER_MIDDLEWARE:
    # This results in no "Access-Control-Allow-Origin: *" header
    app.register_middleware(other_response_middleware, "response")

if __name__ == '__main__':
    app.run()
@ashleysommer
Copy link
Owner

Hi @philipnbbc
Thanks for the bug report.

Sanic-CORS plugin does not yet work with the recently released Sanic v22.9.

It is common when new versions of Sanic come out that it can take several weeks for third-party plugins to updated to include compatibility with the new version.

I am the only developer on this project and have not had a chance to look into Sanic v22.9 yet, or the changes that would be required to add compatibility to Sanic-CORS.

@philipnbbc
Copy link
Author

Thanks @ashleysommer, I appreciate all your efforts developing and maintaining sanic-cors. It's not an immediate problem for us and we can pin to the previous Sanic version.

@ashleysommer
Copy link
Owner

@philipnbbc
I've released a beta version of sanic-cors that should have compatibility with Sanic v22.9+
Can you please install sanic-cors v2.2.0b1 and test if it fixes the problem for you?

@philipnbbc
Copy link
Author

Tested and it works. Thanks!

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

No branches or pull requests

2 participants