Merge pull request #455 from seemethere/add_better_response_error_detection

Adds some safety around response types being wrong
This commit is contained in:
Eli Uriegas 2017-02-17 06:59:52 -06:00 committed by GitHub
commit 55dc45de33

View File

@ -167,12 +167,18 @@ class HttpProtocol(asyncio.Protocol):
# -------------------------------------------- # # -------------------------------------------- #
def write_response(self, response): def write_response(self, response):
keep_alive = (
self.parser.should_keep_alive() and not self.signal.stopped)
try: try:
keep_alive = (
self.parser.should_keep_alive() and not self.signal.stopped)
self.transport.write( self.transport.write(
response.output( response.output(
self.request.version, keep_alive, self.request_timeout)) self.request.version, keep_alive, self.request_timeout))
except AttributeError:
log.error(
('Invalid response object for url {}, '
'Expected Type: HTTPResponse, Actual Type: {}').format(
self.url, type(response)))
self.write_error(ServerError('Invalid response type'))
except RuntimeError: except RuntimeError:
log.error( log.error(
'Connection lost before response written @ {}'.format( 'Connection lost before response written @ {}'.format(