diff --git a/sanic_cors/core.py b/sanic_cors/core.py index 810d4ad..3ac0d0f 100644 --- a/sanic_cors/core.py +++ b/sanic_cors/core.py @@ -50,7 +50,7 @@ supports_credentials=False, max_age=None, send_wildcard=False, - automatic_options=True, + automatic_options=False, vary_header=True, resources=r'/*', intercept_exceptions=True, diff --git a/sanic_cors/decorator.py b/sanic_cors/decorator.py index 3136cdc..7313c51 100644 --- a/sanic_cors/decorator.py +++ b/sanic_cors/decorator.py @@ -105,6 +105,7 @@ def cross_origin(app, *args, **kwargs): _options = kwargs def decorator(f): + nonlocal _options LOG.debug("Enabling %s for cross_origin using options:%s", f, _options) # Sanic does not have the same automatic OPTIONS handling that Flask does, @@ -124,6 +125,7 @@ def decorator(f): # f.provide_automatic_options = False async def wrapped_function(req, *args, **kwargs): + nonlocal _options # Handle setting of Sanic-Cors parameters options = get_cors_options(app, _options) diff --git a/sanic_cors/version.py b/sanic_cors/version.py index 800cf77..0fe3f40 100644 --- a/sanic_cors/version.py +++ b/sanic_cors/version.py @@ -1 +1 @@ -__version__ = '0.4.1.3' +__version__ = '0.4.1.4' diff --git a/tests/extension/test_app_extension.py b/tests/extension/test_app_extension.py index 7a4ae0a..a7a410c 100644 --- a/tests/extension/test_app_extension.py +++ b/tests/extension/test_app_extension.py @@ -223,6 +223,7 @@ def setUp(self): CORS(self.app, resources=r'/api/*', headers='Content-Type', expose_headers='X-Total-Count', + automatic_options=False, origins='http://bar.com') @self.app.route('/api/v1/foo', methods=['GET', 'HEAD', 'OPTIONS']) @@ -234,7 +235,7 @@ def exposed2(request): return json({"success": True}) @self.app.route('/api/v1/special', methods=['GET', 'HEAD', 'OPTIONS']) - @cross_origin(self.app, origins='http://foo.com') + @cross_origin(self.app, origins='http://foo.com', automatic_options=True) def overridden(request): return json({"special": True})