chiark / gitweb /
break out process_request
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 23 Mar 2017 19:10:54 +0000 (19:10 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 23 Mar 2017 19:10:54 +0000 (19:10 +0000)
server

diff --git a/server b/server
index cb9322b..e3fef89 100755 (executable)
--- a/server
+++ b/server
@@ -115,25 +115,27 @@ class Client():
       request = self._rq.popleft()
       request.finish()
 
-class IphttpResource(twisted.web.resource.Resource):
-  isLeaf = True
-  def render_POST(self, request):
-    # find client, update config, etc.
-    metadata = request.args['m']
-    (ci_s, pw, tro) = metadata.split(b'\n')[0:3]
-    ci = ipaddr(ci_s)
-    cl = clients[ci]
-    if pw != cl.pw: raise ValueError('bad password')
+def process_request(request):
+  # find client, update config, etc.
+  metadata = request.args['m']
+  (ci_s, pw, tro) = metadata.split(b'\n')[0:3]
+  ci = ipaddr(ci_s)
+  cl = clients[ci]
+  if pw != cl.pw: raise ValueError('bad password')
 
-    if pw != cl.target_requests_outstanding:
-      raise ...
+  if pw != cl.target_requests_outstanding:
+    raise ...
 
-    try: d = request.args['d']
-    except KeyError: d = ''
+  try: d = request.args['d']
+  except KeyError: d = ''
 
-    cl.process_arriving_data(d)
-    cl.new_request(request)
+  cl.process_arriving_data(d)
+  cl.new_request(request)
 
+class IphttpResource(twisted.web.resource.Resource):
+  isLeaf = True
+  def render_POST(self, request):
+    process_request(request)
   def render_GET(self, request):
     return b'<html><body>hippotat</body></html>'