Skip to content
This repository was archived by the owner on Apr 29, 2022. It is now read-only.

Commit e92aece

Browse files
authored
Merge pull request #31 from robertaistleitner/master
add support for cookies in the websocket
2 parents 02a32b7 + d27c4ba commit e92aece

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

flask_sockets.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from werkzeug.routing import Map, Rule
44
from werkzeug.exceptions import NotFound
5+
from werkzeug.http import parse_cookie
6+
from flask import request
57

68

79
# Monkeys are made for freedom.
@@ -27,9 +29,15 @@ def __call__(self, environ, start_response):
2729
try:
2830
handler, values = adapter.match()
2931
environment = environ['wsgi.websocket']
32+
cookie = None
33+
if 'HTTP_COOKIE' in environ:
34+
cookie = parse_cookie(environ['HTTP_COOKIE'])
3035

3136
with self.app.app_context():
3237
with self.app.request_context(environ):
38+
# add cookie to the request to have correct session handling
39+
request.cookie = cookie
40+
3341
handler(environment, **values)
3442
return []
3543
except (NotFound, KeyError):

0 commit comments

Comments
 (0)