jchitel
jchitel

Reputation: 3169

Google App Engine adding functionality to webapp2.RequestHandler

My GAE app runs into CORS problems with POST requests. I found that the simple solution is to call self.response.headers.add("Access-Control-Allow-Origin", "*") in my request handlers. I would like to not have to call this for every POST handler I write, so I created a mediary class called PostHandler that inherits from webapp2.RequestHandler and that my handlers that deal with POST request will inherit from. This is how I implemented this class:

class PostHandler(webapp2.RequestHandler):
    def __init__(self, request, response):
        super(PostHandler, self).__init__(request, response)
        self.response.headers.add("Access-Control-Allow-Origin", "*")

Will this do what I expect it to do? If I have another handler:

class Login(PostHandler):
    def post(self):
        #blah

Will that handler be a proper webapp2.RequestHandler? Or do I have to do something different?

Upvotes: 2

Views: 538

Answers (1)

Omair Shamshir
Omair Shamshir

Reputation: 2136

I am doing the same thing in this way and its working fine

class PostHandler(webapp2.RequestHandler):
    def dispatch(self):
        self.response.headers['Access-Control-Allow-Origin'] = '*'
        super(PostHandler, self).dispatch()

class Login(PostHandler):
    def post(self):

Upvotes: 4

Related Questions