Merge pull request #8 from channelcat/master
merge upstream master branch
This commit is contained in:
commit
e0e27a671e
|
@ -24,3 +24,4 @@ A list of Sanic extensions created by the community.
|
||||||
- [Sanic-RestPlus](https://github.com/ashleysommer/sanic-restplus): A port of Flask-RestPlus for Sanic. Full-featured REST API with SwaggerUI generation.
|
- [Sanic-RestPlus](https://github.com/ashleysommer/sanic-restplus): A port of Flask-RestPlus for Sanic. Full-featured REST API with SwaggerUI generation.
|
||||||
- [sanic-transmute](https://github.com/yunstanford/sanic-transmute): A Sanic extension that generates APIs from python function and classes, and also generates Swagger UI/documentation automatically.
|
- [sanic-transmute](https://github.com/yunstanford/sanic-transmute): A Sanic extension that generates APIs from python function and classes, and also generates Swagger UI/documentation automatically.
|
||||||
- [pytest-sanic](https://github.com/yunstanford/pytest-sanic): A pytest plugin for Sanic. It helps you to test your code asynchronously.
|
- [pytest-sanic](https://github.com/yunstanford/pytest-sanic): A pytest plugin for Sanic. It helps you to test your code asynchronously.
|
||||||
|
- [jinja2-sanic](https://github.com/yunstanford/jinja2-sanic): a jinja2 template renderer for Sanic.([Documentation](http://jinja2-sanic.readthedocs.io/en/latest/))
|
||||||
|
|
|
@ -10,11 +10,11 @@ You can pass a version number to the routes directly.
|
||||||
from sanic import response
|
from sanic import response
|
||||||
|
|
||||||
|
|
||||||
@app.route('/text', verion=1)
|
@app.route('/text', version=1)
|
||||||
def handle_request(request):
|
def handle_request(request):
|
||||||
return response.text('Hello world! Version 1')
|
return response.text('Hello world! Version 1')
|
||||||
|
|
||||||
@app.route('/text', verion=2)
|
@app.route('/text', version=2)
|
||||||
def handle_request(request):
|
def handle_request(request):
|
||||||
return response.text('Hello world! Version 2')
|
return response.text('Hello world! Version 2')
|
||||||
|
|
||||||
|
|
|
@ -139,7 +139,9 @@ class HttpProtocol(asyncio.Protocol):
|
||||||
self._request_stream_task.cancel()
|
self._request_stream_task.cancel()
|
||||||
if self._request_handler_task:
|
if self._request_handler_task:
|
||||||
self._request_handler_task.cancel()
|
self._request_handler_task.cancel()
|
||||||
exception = RequestTimeout('Request Timeout')
|
try:
|
||||||
|
raise RequestTimeout('Request Timeout')
|
||||||
|
except RequestTimeout as exception:
|
||||||
self.write_error(exception)
|
self.write_error(exception)
|
||||||
|
|
||||||
# -------------------------------------------- #
|
# -------------------------------------------- #
|
||||||
|
@ -317,6 +319,7 @@ class HttpProtocol(asyncio.Protocol):
|
||||||
self.cleanup()
|
self.cleanup()
|
||||||
|
|
||||||
def write_error(self, exception):
|
def write_error(self, exception):
|
||||||
|
response = None
|
||||||
try:
|
try:
|
||||||
response = self.error_handler.response(self.request, exception)
|
response = self.error_handler.response(self.request, exception)
|
||||||
version = self.request.version if self.request else '1.1'
|
version = self.request.version if self.request else '1.1'
|
||||||
|
@ -331,19 +334,22 @@ class HttpProtocol(asyncio.Protocol):
|
||||||
from_error=True)
|
from_error=True)
|
||||||
finally:
|
finally:
|
||||||
if self.has_log:
|
if self.has_log:
|
||||||
extra = {
|
extra = dict()
|
||||||
'status': response.status,
|
if isinstance(response, HTTPResponse):
|
||||||
'host': '',
|
extra['status'] = response.status
|
||||||
'request': str(self.request) + str(self.url)
|
|
||||||
}
|
|
||||||
if response and isinstance(response, HTTPResponse):
|
|
||||||
extra['byte'] = len(response.body)
|
extra['byte'] = len(response.body)
|
||||||
else:
|
else:
|
||||||
|
extra['status'] = 0
|
||||||
extra['byte'] = -1
|
extra['byte'] = -1
|
||||||
if self.request:
|
if self.request:
|
||||||
extra['host'] = '%s:%d' % self.request.ip,
|
extra['host'] = '%s:%d' % self.request.ip,
|
||||||
extra['request'] = '%s %s' % (self.request.method,
|
extra['request'] = '%s %s' % (self.request.method,
|
||||||
self.url)
|
self.url)
|
||||||
|
else:
|
||||||
|
extra['host'] = 'UNKNOWN'
|
||||||
|
extra['request'] = 'nil'
|
||||||
|
if self.parser and not (self.keep_alive
|
||||||
|
and extra['status'] == 408):
|
||||||
netlog.info('', extra=extra)
|
netlog.info('', extra=extra)
|
||||||
self.transport.close()
|
self.transport.close()
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ def handler_3(request):
|
||||||
|
|
||||||
@exception_handler_app.route('/4')
|
@exception_handler_app.route('/4')
|
||||||
def handler_4(request):
|
def handler_4(request):
|
||||||
foo = bar
|
foo = bar # noqa -- F821 undefined name 'bar' is done to throw exception
|
||||||
return text(foo)
|
return text(foo)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user