Skip to content

Commit

Permalink
allow connect event handler to send data to client
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Jun 29, 2015
1 parent 61e5121 commit a0dbf69
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions engineio/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,22 @@ def handle_request(self, environ, start_response):
def _handle_connect(self, environ):
"""Handle a client connection request."""
sid = self.generate_id()
if self._trigger_event('connect', sid, environ) is False:
self.logger.warning('Application rejected connection')
return self._unauthorized()
self.clients[sid] = socket.Socket(self, sid)
s = socket.Socket(self, sid)
self.clients[sid] = s
pkt = packet.Packet(
packet.OPEN, {'sid': sid,
'upgrades': self._upgrades(sid),
'pingTimeout': int(self.ping_timeout * 1000),
'pingInterval': int(self.ping_interval * 1000)})
s.send(pkt)
if self._trigger_event('connect', sid, environ) is False:
self.logger.warning('Application rejected connection')
del self.clients[sid]
return self._unauthorized()
headers = None
if self.cookie:
headers = [('Set-Cookie', self.cookie + '=' + sid)]
return self._ok([pkt], headers=headers)
return self._ok(s.poll(), headers=headers)

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

0 comments on commit a0dbf69

Please sign in to comment.