blueberryfields
blueberryfields

Reputation: 50488

Can I/How do I access client side cookies through a websocket connection to a twisted app?

i have a simple twisted application, with the websockets module. the application is serving a lineReceiver protocol, and i'd like to inspect the contents of incoming connections, including seeing which cookies are set on them, something like this:

class Echo(basic.lineReceiver):
    def connectionMade(self):
        print "Got new client!"
        #print request.cookies

is it possible for me to access request (client-side) cookies from a protocol that's served over websockets? if so, how do I do it?

Upvotes: 1

Views: 1464

Answers (1)

oberstet
oberstet

Reputation: 22051

Here is a complete example that includes a WebSocket client and a server that set/get custom HTTP headers. Adapting this you can access cookies sent by e.g. a browser during the initial WebSocket opening handshake on server-side.

Disclosure: I am original author of Autobahn and work for Tavendo.

Upvotes: 4

Related Questions