Last active
September 8, 2017 15:36
-
-
Save hatarist/7644fccf15f3179c6ae94e76c9eb02e5 to your computer and use it in GitHub Desktop.
A quick Sanic workaround that doesn't complain about weird HTTP 408 errors that lead to the blank access.log entries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sanic.exceptions import RequestTimeout | |
from sanic.server import HttpProtocol | |
class NoTimeoutHttpProtocol(HttpProtocol): | |
""" | |
Doesn't complain about request timeouts to the logger. | |
Usage: | |
app = Sanic() | |
app.run(..., protocol=NoTimeoutHttpProtocol) | |
""" | |
def write_error(self, exception): | |
if isinstance(exception, RequestTimeout): | |
response = self.error_handler.response(self.request, exception) | |
version = self.request.version if self.request else '1.1' | |
self.transport.write(response.output(version)) | |
self.transport.close() | |
else: | |
return super().write_error(exception) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment