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

Commit

Permalink
Merge pull request #31 from robertaistleitner/master
Browse files Browse the repository at this point in the history
add support for cookies in the websocket
  • Loading branch information
kennethreitz authored May 1, 2017
2 parents 02a32b7 + d27c4ba commit e92aece
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions flask_sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from werkzeug.routing import Map, Rule
from werkzeug.exceptions import NotFound
from werkzeug.http import parse_cookie
from flask import request


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

with self.app.app_context():
with self.app.request_context(environ):
# add cookie to the request to have correct session handling
request.cookie = cookie

handler(environment, **values)
return []
except (NotFound, KeyError):
Expand Down

0 comments on commit e92aece

Please sign in to comment.