Skip to content

Commit

Permalink
Allow WebSocketWSGIHandler to work even in presence of a middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
bozzzzo committed Feb 4, 2016
1 parent f092a41 commit a25fc2d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ws4py/server/wsgirefserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
"""
import logging
import sys
import itertools
import operator
from wsgiref.handlers import SimpleHandler
from wsgiref.simple_server import WSGIRequestHandler, WSGIServer as _WSGIServer
from wsgiref import util
Expand Down Expand Up @@ -63,6 +65,12 @@ def finish_response(self):
- Attach the returned websocket, if any, to the WSGI server
using its ``link_websocket_to_server`` method.
"""
# force execution of the result iterator until first actual content
rest = iter(self.result)
first = list(itertools.islice(rest, 1))
self.result = itertools.chain(first, rest)

# now it's safe to look if environ was modified
ws = None
if self.environ:
self.environ.pop('ws4py.socket', None)
Expand Down

0 comments on commit a25fc2d

Please sign in to comment.