Mercurial > cosocket
changeset 89:8105e7a95e8a
Enforced maximum message size.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Fri, 01 May 2009 17:13:56 -0700 |
parents | ce5060140af5 |
children | 0b8c3a21335c |
files | openwebchat.py |
diffstat | 1 files changed, 10 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/openwebchat.py Fri May 01 17:07:18 2009 -0700 +++ b/openwebchat.py Fri May 01 17:13:56 2009 -0700 @@ -18,6 +18,7 @@ KEEP_ALIVE_MAX_REQUESTS = 99 KEEP_ALIVE_TIMEOUT = int(DEFAULT_TIMEOUT) +MAX_MESSAGE_SIZE = 8192 class Conversations(object): def __init__(self): @@ -198,11 +199,15 @@ yield channels.until_message_received(conv_name) elif page == 'send': length = int(headers.getheader('Content-Length', 0)) - msg = yield until_received(bytes = length) - conv = self._convs.get(conv_name) - conv.append(json.loads(msg)) - yield channels.until_message_sent(conv_name, None) - yield self._until_http_response_sent('sent.') + if length == 0 or length > MAX_MESSAGE_SIZE: + yield self._until_http_response_sent('message too large', + code = 413) + else: + msg = yield until_received(bytes = length) + conv = self._convs.get(conv_name) + conv.append(json.loads(msg)) + yield channels.until_message_sent(conv_name, None) + yield self._until_http_response_sent('sent.') elif page == '': yield self._until_file_sent('openwebchat.html') else: