Created
January 13, 2015 21:09
-
-
Save bengrunfeld/cd11750d16caacea79e1 to your computer and use it in GitHub Desktop.
Webapp2 Headers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Sometimes you need to forcefully set headers in Webapp2 while using Google App Engine (GAE). | |
It is NOT RECOMMENDED to use `*` for `Access-Control-Allow-Origin` as below. I've put it | |
there simply for the sake of demonstration. Make sure you choose something more restrictive. | |
""" | |
def initialize_headers(headers, http_verb): | |
"""Set up the headers for HTTP requests""" | |
headers['Access-Control-Allow-Origin'] = '*' | |
headers['Access-Control-Allow-Methods'] = http_verb | |
headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept' | |
headers['Content-Type'] = 'text/plain' | |
return headers | |
class HandleOptions(webapp2.RequestHandler): | |
def options(self): | |
"""GET /: Retrieve all todos""" | |
self.response.headers = initialize_headers(self.response.headers, 'OPTIONS') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment