Question

I am using Google App Engine's Protocol RPC library. I want to get the headers for a request and check that a certain header exists. I can't figure out how to get the requests headers?

The code basically looks like this:

class MyService(remote.Service):
    @remote.method(MyRequest, MyResponse)
    def my_request(self, request):
        # TODO: Check that header exists in request

The passed in request object is of the type 'MyRequest' and doesn't have any header information attached to it.

Was it helpful?

Solution

There is a special method initialize_request_state that allows you to access all of the requests headers.

class MyService(remote.Service):

    def initialize_request_state(self, state):
        self.headers = state.headers

    @remote.method(MyRequest, MyResponse)
    def my_request(self, request):
        logging.debug(self.headers)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top