Mercurial > bitten > bitten-test
comparison bitten/master.py @ 872:f320205ca1f9
Ensure that master only sends utf-8 bodies (especially errors are prone to contain strings of unknown origin, potentially unicode).
author | osimons |
---|---|
date | Tue, 19 Oct 2010 20:55:13 +0000 |
parents | 59acaa8b52c0 |
children |
comparison
equal
deleted
inserted
replaced
870:c837eaf8ff2e | 872:f320205ca1f9 |
---|---|
141 | 141 |
142 # Internal methods | 142 # Internal methods |
143 | 143 |
144 def _send_response(self, req, code=200, body='', headers=None): | 144 def _send_response(self, req, code=200, body='', headers=None): |
145 """ Formats and sends the response, raising ``RequestDone``. """ | 145 """ Formats and sends the response, raising ``RequestDone``. """ |
146 if isinstance(body, unicode): | |
147 body = body.encode('utf-8') | |
146 req.send_response(code) | 148 req.send_response(code) |
147 headers = headers or {} | 149 headers = headers or {} |
148 headers.setdefault('Content-Length', len(body)) | 150 headers.setdefault('Content-Length', len(body)) |
149 for header in headers: | 151 for header in headers: |
150 req.send_header(header, headers[header]) | 152 req.send_header(header, headers[header]) |