Skip to content

Commit

Permalink
Added b64 checks and encoding during initial connect
Browse files Browse the repository at this point in the history
  • Loading branch information
meismyles committed Aug 29, 2015
1 parent 22878da commit ac90ed6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions engineio/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def __init__(self, async_mode=None, ping_timeout=60, ping_interval=25,
else:
self.logger.setLevel(logging.ERROR)
self.logger.addHandler(logging.StreamHandler())

if async_mode is None:
modes = ['eventlet', 'gevent', 'threading']
else:
Expand Down Expand Up @@ -185,10 +184,13 @@ def handle_request(self, environ, start_response):
r = self._bad_request()
else:
sid = query['sid'][0] if 'sid' in query else None
b64 = query['b64'][0] if 'b64' in query else False
b64 = False
if 'b64' in query:
if query['b64'][0] == "1" or query['b64'][0].lower() == "true":
b64 = True
if method == 'GET':
if sid is None:
r = self._handle_connect(environ)
r = self._handle_connect(environ, b64)
else:
if sid not in self.sockets:
self.logger.warning('Invalid session %s', sid)
Expand Down Expand Up @@ -234,7 +236,7 @@ def _generate_id(self):
"""Generate a unique session id."""
return uuid.uuid4().hex

def _handle_connect(self, environ):
def _handle_connect(self, environ, b64=False):
"""Handle a client connection request."""
sid = self._generate_id()
s = socket.Socket(self, sid)
Expand All @@ -252,7 +254,7 @@ def _handle_connect(self, environ):
headers = None
if self.cookie:
headers = [('Set-Cookie', self.cookie + '=' + sid)]
return self._ok(s.poll(), headers=headers)
return self._ok(s.poll(), headers=headers, b64=b64)

def _upgrades(self, sid):
"""Return the list of possible upgrades for a client connection."""
Expand Down

0 comments on commit ac90ed6

Please sign in to comment.