Mercurial > cosocket
changeset 14:545927beb490
Added an example MIME multipart/mixed response to the example server.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sun, 19 Apr 2009 13:24:23 -0700 |
parents | 65482f4e2555 |
children | 71e093cafa69 |
files | example.py |
diffstat | 1 files changed, 12 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/example.py Sun Apr 19 12:55:38 2009 -0700 +++ b/example.py Sun Apr 19 13:24:23 2009 -0700 @@ -12,8 +12,18 @@ request_headers = yield until_received(terminator = '\r\n\r\n') req_parts = request_line.split() if req_parts[1] == '/listen': - ip = yield channels.until_message_received('global') - yield until_sent(_make_http_response('send from %s.' % ip)) + yield until_sent('HTTP/1.1 200 OK\r\n' + + 'Content-Type: multipart/mixed; ' + + 'boundary="chunk"\r\n\r\n') + i = 0 + while 1: + i += 1 + ip = yield channels.until_message_received('global') + msg = 'Got message %d from %s.\r\n' % (i, ip) + yield until_sent('--chunk\r\n' + + 'Content-Length: %d\r\n' % len(msg) + + 'Content-Type: text/plain\r\n\r\n' + + msg) elif req_parts[1] == '/send': yield channels.until_message_sent('global', addr[0]) yield until_sent(_make_http_response('sent.'))