Skip to content

Commit

Permalink
Add WSGIRequest subclass for HTTPS env var support
Browse files Browse the repository at this point in the history
  • Loading branch information
pmac committed May 3, 2017
1 parent 320e90e commit 8124b66
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions wsgi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,25 @@
else:
newrelic = False

IS_HTTPS = os.environ.get('HTTPS', '').strip() == 'on'
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bedrock.settings')

# must be imported after env var is set above.
from django.core.handlers.wsgi import WSGIRequest
from django.core.wsgi import get_wsgi_application
from raven.contrib.django.raven_compat.middleware.wsgi import Sentry


class WSGIHTTPSRequest(WSGIRequest):
def _get_scheme(self):
if IS_HTTPS:
return 'https'

return super(WSGIHTTPSRequest, self)._get_scheme()


application = get_wsgi_application()
application.request_class = WSGIHTTPSRequest
application = Sentry(application)

if newrelic:
Expand Down

0 comments on commit 8124b66

Please sign in to comment.