I'm trying to get headers, more specifically cookies, from the overwrote opened method (or any method before or during received_message, really).
I'm using the current build from pip, everything is working fine as far as the echo server goes, just can't seem to find how to get headers from the WebSocketProtocol .
I see in the Protocol wrapper, that the headers are being read from a generator during the handshake, so I know their being processed, just not stored anywhere for access. I was curious if there was a way to access these via my WSServer class. I don't mind having to overwrite a method if possible and carry the maintained of updates to it as the code base is fairly small and easily diffed. I'm assuming I'm going to need to extend WebSocketProtocol into my own class and overwrite either read_headers or handle_initial_handshake (I'd prefer the read_headers over handle hand shake for obvious reasons if this is my only option).
My intent is to incorporate the existing session handling of my previous application so that it can fail-over to regular ajax polling already implemented for non-evergreen browsers.
# Actual SERVER.
def _server(self):
set_process_name(self.__nameFull__)
self.__loop = asyncio.get_event_loop()
def start_server():
factory = lambda: WebSocketProtocol(WSServer)
return self.__loop.create_server(factory, self.__bind, self.__port)
s = self.__loop.run_until_complete(start_server())
print(self.__nameFull__, 'serving on', s.sockets[0].getsockname())
self.__loop.run_forever()
print(self.__loop.is_running())
class WSServer(WebSocket):
def opened(self):
print("OPENED")
headers = yield from self.proto.read_headers()
print(headers.get('Cookie'))
def received_message(self, message):
# p(debug_object(self.connection))
# print("\n\n\n\n\n")
# p(debug_object(message))
self.send(message.data, message.is_binary)