Skip to content

Commit

Permalink
Fixed a long-standing problem, where Sanic-CORS would prevent any oth…
Browse files Browse the repository at this point in the history
…er middleware from running, after CORS had run.

This is due to a nuance in the way that Sanic runs response middlewares, and how it interprets the return value.
  • Loading branch information
ashleysommer committed Sep 26, 2017
1 parent 077a048 commit fee3007
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sanic==0.6.0
sanic>=0.6.0
7 changes: 3 additions & 4 deletions sanic_cors/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,17 @@ async def cors_response_middleware(req, resp):
nonlocal resources
# `resp` can be None in the case of using Websockets
if resp is None:
return None
return False

if SANIC_0_4_1 < SANIC_VERSION and req.headers.get(SANIC_CORS_SKIP_RESPONSE_MIDDLEWARE):
LOG.debug('CORS was handled in the exception handler, skipping')
# On Sanic > 0.4.1, an exception might already have CORS middleware run on it.
return resp
return False

# If CORS headers are set in a view decorator, pass
elif req.headers.get(SANIC_CORS_EVALUATED):
LOG.debug('CORS have been already evaluated, skipping')
return resp
return False

try:
path = req.path
Expand All @@ -260,5 +260,4 @@ async def cors_response_middleware(req, resp):
break
else:
LOG.debug('No CORS rule matches')
return resp
return cors_response_middleware
2 changes: 1 addition & 1 deletion sanic_cors/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.6.0.1'
__version__ = '0.6.0.2'

0 comments on commit fee3007

Please sign in to comment.