Merge branch 'master' of github.com:channelcat/sanic into add_app_loop_safety
This commit is contained in:
commit
c75d484f23
|
@ -1,7 +1,7 @@
|
||||||
[run]
|
[run]
|
||||||
branch = True
|
branch = True
|
||||||
source = sanic, tests
|
source = sanic
|
||||||
omit = site-packages
|
omit = site-packages, sanic/utils.py
|
||||||
|
|
||||||
[html]
|
[html]
|
||||||
directory = coverage
|
directory = coverage
|
||||||
|
|
|
@ -11,3 +11,4 @@ A list of Sanic extensions created by the community.
|
||||||
- [Pagination](https://github.com/lixxu/python-paginate): Simple pagination support.
|
- [Pagination](https://github.com/lixxu/python-paginate): Simple pagination support.
|
||||||
- [Motor](https://github.com/lixxu/sanic-motor): Simple motor wrapper.
|
- [Motor](https://github.com/lixxu/sanic-motor): Simple motor wrapper.
|
||||||
- [Sanic CRUD](https://github.com/Typhon66/sanic_crud): CRUD REST API generation with peewee models.
|
- [Sanic CRUD](https://github.com/Typhon66/sanic_crud): CRUD REST API generation with peewee models.
|
||||||
|
- [UserAgent](https://github.com/lixxu/sanic-useragent): Add `user_agent` to request
|
||||||
|
|
|
@ -167,19 +167,26 @@ 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(
|
||||||
self.request.ip))
|
self.request.ip))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.bail_out(
|
self.bail_out(
|
||||||
"Writing response failed, connection closed {}".format(e))
|
"Writing response failed, connection closed {}".format(
|
||||||
|
repr(e)))
|
||||||
finally:
|
finally:
|
||||||
if not keep_alive:
|
if not keep_alive:
|
||||||
self.transport.close()
|
self.transport.close()
|
||||||
|
@ -196,10 +203,10 @@ class HttpProtocol(asyncio.Protocol):
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
log.error(
|
log.error(
|
||||||
'Connection lost before error written @ {}'.format(
|
'Connection lost before error written @ {}'.format(
|
||||||
self.request.ip))
|
self.request.ip if self.request else 'Unknown'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.bail_out(
|
self.bail_out(
|
||||||
"Writing error failed, connection closed {}".format(e),
|
"Writing error failed, connection closed {}".format(repr(e)),
|
||||||
from_error=True)
|
from_error=True)
|
||||||
finally:
|
finally:
|
||||||
self.transport.close()
|
self.transport.close()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user