Mercurial > cosocket
changeset 29:02b9a564d841
More refactoring.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Mon, 27 Apr 2009 10:53:15 -0700 |
parents | 91c47c54b666 |
children | e5b85cdd7228 |
files | openwebchat.py |
diffstat | 1 files changed, 14 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/openwebchat.py Mon Apr 27 10:35:48 2009 -0700 +++ b/openwebchat.py Mon Apr 27 10:53:15 2009 -0700 @@ -32,16 +32,11 @@ 'Keep-Alive: timeout=99, max=99', 'Connection: Keep-Alive', 'Content-Length: %d' % length, - 'Content-Type: %s\r\n' % mimetype, + 'Content-Type: %s' % mimetype, + '', msg)) yield until_sent(content) - def _make_chunk(self, msg, mimetype = 'text/plain'): - return ('Content-Length: %d\r\n' % len(msg) + - 'Content-Type: text/plain\r\n\r\n' + - msg + - '\r\n--chunk\r\n') - def _until_file_sent(self, filename): mimetype = self.MIME_TYPES[filename.split('.')[-1]] @@ -71,13 +66,21 @@ request_headers = request[1:] req_parts = request_line.split() if req_parts[1] == '/listen': - yield until_sent('HTTP/1.1 200 OK\r\n' + - 'Content-Type: multipart/x-mixed-replace; ' + - 'boundary="chunk"\r\n\r\n--chunk\r\n') + yield self._until_http_response_sent( + '--chunk\r\n', + mimetype = ('Content-Type: multipart/x-mixed-replace; ' + + 'boundary="chunk"')) while 1: ip, num = yield channels.until_message_received('global') msg = 'Got message %d from %s.' % (num, ip) - yield until_sent(self._make_chunk(msg)) + yield until_sent('\r\n'.join( + ('Content-Length: %d' % len(msg), + 'Content-Type: text/plain', + '', + msg, + '', + '--chunk', + ''))) elif req_parts[1] == '/send': yield channels.until_message_sent('global', (addr[0], num_messages))