mirror of
https://github.com/kennethreitz/flask-sockets.git
synced 2026-06-05 23:10:16 +00:00
add support for cookies in the websocket
if cookies are used for session handling, please note that you have to persist your session manually.
something like ```self.app.save_session(session, make_response(""))``` after messages are received does the trick.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from werkzeug.routing import Map, Rule
|
||||
from werkzeug.exceptions import NotFound
|
||||
from werkzeug.http import parse_cookie
|
||||
from flask import request
|
||||
|
||||
def log_request(self):
|
||||
log = self.server.log
|
||||
@@ -37,9 +39,13 @@ class SocketMiddleware(object):
|
||||
try:
|
||||
handler, values = adapter.match()
|
||||
environment = environ['wsgi.websocket']
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user