Skip to content

Commit

Permalink
Default app-wide automatic_options to False, as it fits Sanic's minim…
Browse files Browse the repository at this point in the history
…al feel better.

Fixed a failing test caused by app-wide automatic_options implementation.
Bumped version.
  • Loading branch information
ashleysommer committed Apr 18, 2017
1 parent 6da7cea commit bcb9dd0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sanic_cors/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions sanic_cors/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion sanic_cors/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.4.1.3'
__version__ = '0.4.1.4'
3 changes: 2 additions & 1 deletion tests/extension/test_app_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand All @@ -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})

Expand Down

0 comments on commit bcb9dd0

Please sign in to comment.