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

add support for cookies in the websocket #31

Merged
merged 2 commits into from
May 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions flask_sockets.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -37,9 +39,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