Skip to content

Commit

Permalink
Only send STS header if request.is_secure(). Fixes #5.
Browse files Browse the repository at this point in the history
  • Loading branch information
James Socol committed Mar 7, 2012
1 parent de48d09 commit 8eeab71
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions commonware/response/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ class StrictTransportMiddleware(object):
"""

def process_response(self, request, response):
age = getattr(settings, 'STS_MAX_AGE', 2592000) # 30 days.
subdomains = getattr(settings, 'STS_SUBDOMAINS', False)
val = 'max-age=%d' % age
if subdomains:
val += '; includeSubDomains'
response['Strict-Transport-Security'] = val
if request.is_secure():
age = getattr(settings, 'STS_MAX_AGE', 2592000) # 30 days.
subdomains = getattr(settings, 'STS_SUBDOMAINS', False)
val = 'max-age=%d' % age
if subdomains:
val += '; includeSubDomains'
response['Strict-Transport-Security'] = val
return response


Expand Down

0 comments on commit 8eeab71

Please sign in to comment.