Skip to content

Commit

Permalink
set HSTS header
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Sep 1, 2016
1 parent 3c8e78b commit 2f35cdb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
7 changes: 6 additions & 1 deletion activitystreams.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,12 @@ def write_response(self, response, actor=None, url=None, title=None):

activities = response['items']

self.response.headers['Access-Control-Allow-Origin'] = '*'
self.response.headers.update({
'Access-Control-Allow-Origin': '*',
'Strict-Transport-Security':
'max-age=16070400; includeSubDomains; preload', # 6 months
})

if format in ('json', 'activitystreams'):
self.response.headers['Content-Type'] = 'application/json'
self.response.out.write(json.dumps(response, indent=2))
Expand Down
14 changes: 11 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@
URL_CACHE_TIME = 5 * 60 # 5m


class FrontPageHandler(handlers.TemplateHandler):
class Handler(webapp2.RequestHandler):
"""Base handler class that adds the HSTS header."""
def __init__(self, *args, **kwargs):
super(Handler, self).__init__(*args, **kwargs)
self.response.headers['Strict-Transport-Security'] = \
'max-age=16070400; includeSubDomains; preload' # 6 months


class FrontPageHandler(handlers.TemplateHandler, Handler):
"""Renders and serves the front page."""
handle_exception = handlers.handle_exception

Expand All @@ -62,7 +70,7 @@ def template_vars(self):
return vars


class DemoHandler(webapp2.RequestHandler):
class DemoHandler(Handler):
"""Handles silo requests from the interactive demo form on the front page."""
handle_exception = handlers.handle_exception

Expand Down Expand Up @@ -90,7 +98,7 @@ def get(self):
urllib.urlencode(params)))


class UrlHandler(activitystreams.Handler):
class UrlHandler(activitystreams.Handler, Handler):
"""Handles AS/mf2 requests from the interactive demo form on the front page.
Fetched URL data is cached for 5m. Cache key is 'U [URL]', value is dict with
Expand Down

0 comments on commit 2f35cdb

Please sign in to comment.