-
Notifications
You must be signed in to change notification settings - Fork 22
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
Allow-Control-Access-Origin header duplicated or none present in headers. #48
Comments
Hi @ray-t1 |
I also had a same issue. When the request handler didn't raise any error, the 'Access-Control-Allow-Origin' header is correctly present on the response header, otherwise, when the app raises an exception while processing a request, that header is not present and the browser console logs CORS error message. app = Sanic("car_locator")
@app.middleware("response")
async def update_headers(request, response):
origin = request.headers.get("origin")
response.headers.update({"Access-Control-Allow-Origin": origin}) |
I'm using sanic_cors 0.10.0.post1 with sanic_jwt_extended and also getting double headers in OPTIONS.
And here is the code for this: from sanic import Sanic
from sanic.response import text
from sanic_cors import CORS
from sanic_jwt_extended import JWTManager, create_access_token, jwt_required
app = Sanic(__name__)
CORS(app, automatic_options=True)
# Setup the Sanic-JWT-Extended extension
app.config["JWT_SECRET_KEY"] = "my_secret"
JWTManager(app)
@app.route("/", ["GET"])
@jwt_required
async def index(request):
return text("hello")
@app.route("/login", ["GET"])
async def login(request):
return text(await create_access_token(request.app, identity="user"))
if __name__ == "__main__":
app.run(port=7000, debug=True) sanic: 19.9.0 Edit: sanic_cors v.0.10.0.post3 solves this |
@lahsuk @ray-t1 You titled this post "duplicated or not present in headers" however your post is only about not-present headers. What is the issue you are seeing with duplicated? |
@ashleysommer yes, the first problem that I encountered in 0.10.0.post1 was duplicate headers. Since this issue has the same title, I thought it would go here. |
I've seen both, duplicated and non present headers. I have a custom error handler and find out a workaround for specific error codes (that's how i handle the various errors in my system) adding the CORS header if not present or removing it if it is duplicated. |
Hello to everyone. I've been using Sanic-Cors for a while now and there's never been any bug or conflict, however i'm getting this message :
**Access to XMLHttpRequest at 'https://srv.celpago.com/bank/plaid/issue' from origin 'https://dev.celpago.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.**
when handling error responses for some endpoints.I'm using Sanic 20.6.3 and i don't know if incompability exists for this version. I disabled
**automatic_options**
to handle preflight requests myself but didn't work either. Any clue on what could be causing this?The text was updated successfully, but these errors were encountered: