Mercurial > cosocket
changeset 31:041bda62b614
More refactorings.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Mon, 27 Apr 2009 11:44:38 -0700 |
parents | e5b85cdd7228 |
children | 1acccfa6a4f6 |
files | openwebchat.py |
diffstat | 1 files changed, 11 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/openwebchat.py Mon Apr 27 11:13:54 2009 -0700 +++ b/openwebchat.py Mon Apr 27 11:44:38 2009 -0700 @@ -24,17 +24,20 @@ def _until_http_response_sent(self, msg = '', mimetype = 'text/plain', length = None, code = 200): - content = '\r\n'.join( - ('HTTP/1.1 %d %s' % (code, - httplib.responses[code]), - 'Keep-Alive: timeout=99, max=99', - 'Connection: Keep-Alive', - 'Content-Type: %s' % mimetype)) + headers = {'Keep-Alive': 'timeout=99, max=99', + 'Connection': 'Keep-Alive', + 'Content-Type': mimetype} if not mimetype.startswith('multipart'): if length is None: length = len(msg) - content += '\r\nContent-Length: %d' % length - content += '\r\n\r\n%s' % msg + headers['Content-Length'] = str(length) + + header_lines = ['HTTP/1.1 %d %s' % (code, + httplib.responses[code])] + header_lines.extend(['%s: %s' % (key, value) + for key, value in headers.items()]) + header_lines.extend(['', msg]) + content = '\r\n'.join(header_lines) yield until_sent(content) def _until_file_sent(self, filename):