Commit 911cdf80 authored by Denis Bilenko's avatar Denis Bilenko

http: add _on_full() method to HTTPServer that implements replying with 503 error

the old way of settings _default_response_code is no longer supported by core
parent b40c0b75
......@@ -26,10 +26,17 @@ class HTTPServer(BaseServer):
self.handle(request)
else:
if self.full():
request._default_response_code = 503
self._on_full(request)
else:
spawn(self.handle, request)
def _on_full(self, request):
msg = 'Service Temporarily Unavailable'
request.add_output_header('Connection', 'close')
request.add_output_header('Content-type', 'text/plain')
request.add_output_header('Content-length', str(len(msg)))
request.send_reply(503, 'Service Unavailable', msg)
def start_accepting(self):
self.http = core.http(self._on_request)
self.http.accept(self.socket.fileno())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment