Skip to content

Commit

Permalink
Add extra stuff to the WSGI environ sent during invites
Browse files Browse the repository at this point in the history
Also set SERVER_NAME and SERVER_PORT for consistency, and set up a
vendor CKAN key to be able to identify the environ as one of the ones
used for sending the WSGI invites. This is needed so the `is_flask`
function correctly returns the relevant value based on the request
environ.
  • Loading branch information
amercader committed Jun 8, 2016
1 parent c9cef38 commit 45371da
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion ckan/common.py
Expand Up @@ -31,7 +31,9 @@ def is_flask():
Currently using the presence of `flask.request`, though we may want to
change that for something more robust.
'''
if flask.request:
if (flask.request and
(flask.request.environ.get('ckan.app') == 'flask_app' or
flask.request.environ.get('ckan.wsgiparty.setup'))):
return True
else:
return False
Expand Down
13 changes: 10 additions & 3 deletions ckan/config/middleware/__init__.py
Expand Up @@ -99,12 +99,19 @@ def send_invitations(self, apps):
PATH = '/__invite__/'
# We need to send an environ tailored to `ckan.site_url`, otherwise
# Flask will return a 404 for the invite path (as we are using
# SERVER_NAME). Existance of `ckan.site_url` in config has already
# been checked.
# SERVER_NAME on Flask config). Existance of `ckan.site_url` in config
# has already been checked.
# Also add a key to be able to identify this request environ as a WSGI
# party setup one.
parts = urlparse.urlparse(config.get('ckan.site_url'))
environ_overrides = {
'HTTP_HOST': parts.netloc,
'HTTP_HOST': str(parts.netloc),
'SERVER_NAME': str(parts.hostname),
'ckan.wsgiparty.setup': True,
}
if parts.port:
environ_overrides['SERVER_PORT'] = str(parts.port)

for app_name, app in apps.items():
environ = create_environ(PATH, environ_overrides=environ_overrides)
environ[self.partyline_key] = self.operator_class(self)
Expand Down

0 comments on commit 45371da

Please sign in to comment.