summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ara/clients/offline.py35
1 files changed, 6 insertions, 29 deletions
diff --git a/ara/clients/offline.py b/ara/clients/offline.py
index 3dc5cd8..8cf15b7 100644
--- a/ara/clients/offline.py
+++ b/ara/clients/offline.py
@@ -23,7 +23,7 @@ import os
23import threading 23import threading
24 24
25from django.core.handlers.wsgi import WSGIHandler 25from django.core.handlers.wsgi import WSGIHandler
26from django.core.servers.basehttp import ServerHandler as BaseServerHandler, ThreadedWSGIServer, WSGIRequestHandler 26from django.core.servers.basehttp import ThreadedWSGIServer, WSGIRequestHandler
27 27
28from .http import AraHttpClient 28from .http import AraHttpClient
29 29
@@ -60,34 +60,6 @@ class AraOfflineClient(AraHttpClient):
60 raise self.server_thread.error 60 raise self.server_thread.error
61 61
62 62
63class ServerHandler(BaseServerHandler):
64 def cleanup_headers(self):
65 super().cleanup_headers()
66 self.headers["Connection"] = "close"
67
68
69class QuietWSGIRequestHandler(WSGIRequestHandler):
70 def log_message(*args):
71 pass
72
73 def handle(self):
74 """Copy of WSGIRequestHandler.handle() but with different ServerHandler"""
75 self.raw_requestline = self.rfile.readline(65537)
76 if len(self.raw_requestline) > 65536:
77 self.requestline = ""
78 self.request_version = ""
79 self.command = ""
80 self.send_error(414)
81 return
82
83 if not self.parse_request(): # An error code has been sent, just exit
84 return
85
86 handler = ServerHandler(self.rfile, self.wfile, self.get_stderr(), self.get_environ())
87 handler.request_handler = self # backpointer for logging
88 handler.run(self.server.get_app())
89
90
91class ServerThread(threading.Thread): 63class ServerThread(threading.Thread):
92 def __init__(self, host, port=0): 64 def __init__(self, host, port=0):
93 self.host = host 65 self.host = host
@@ -116,3 +88,8 @@ class ServerThread(threading.Thread):
116 88
117 def _create_server(self): 89 def _create_server(self):
118 return ThreadedWSGIServer((self.host, self.port), QuietWSGIRequestHandler, allow_reuse_address=False) 90 return ThreadedWSGIServer((self.host, self.port), QuietWSGIRequestHandler, allow_reuse_address=False)
91
92
93class QuietWSGIRequestHandler(WSGIRequestHandler):
94 def log_message(*args):
95 pass