chiark / gitweb /
wip
[hippotat.git] / server
diff --git a/server b/server
index 6a71bfd5b8f1452da80e2ad0c7efcb8de553bd7d..8a16c34a390d6d195430f5b7f3e06163283b65ff 100755 (executable)
--- a/server
+++ b/server
@@ -12,8 +12,6 @@ from twisted.web.server import NOT_DONE_YET
 
 import syslog
 
 
 import syslog
 
-import traceback
-
 clients = { }
 
 #---------- "router" ----------
 clients = { }
 
 #---------- "router" ----------
@@ -100,6 +98,10 @@ class Client():
     self._rq.append(request)
     self._check_outbound()
 
     self._rq.append(request)
     self._check_outbound()
 
+  def _req_write(self, req, d):
+    self._log(DBG.HTTP, 'req_write ', idof=req, d=d)
+    req.write(d)
+
   def _check_outbound(self):
     log_debug(DBG.HTTP_CTRL, 'CHKO')
     while True:
   def _check_outbound(self):
     log_debug(DBG.HTTP_CTRL, 'CHKO')
     while True:
@@ -123,7 +125,7 @@ class Client():
       self._log(DBG.HTTP_CTRL, 'CHKO processing', idof=request)
       # request, and also some non-expired packets
       self._pq.process((lambda: request.sentLength),
       self._log(DBG.HTTP_CTRL, 'CHKO processing', idof=request)
       # request, and also some non-expired packets
       self._pq.process((lambda: request.sentLength),
-                       request.write,
+                       (lambda d: self._req_write(request, d)),
                        self.max_batch_down)
 
       assert(request.sentLength)
                        self.max_batch_down)
 
       assert(request.sentLength)
@@ -158,18 +160,25 @@ def process_request(request, desca):
   try:
     d = request.args[b'd'][0]
     desca['d'] = d
   try:
     d = request.args[b'd'][0]
     desca['d'] = d
-  except KeyError: d = b''
+    desca['dlen'] = len(d)
+  except KeyError:
+    d = b''
+    desca['dlen'] = None
+
+  log_http(desca, 'processing', idof=id(request), d=d)
+
+  d = mime_translate(d)
 
   cl.process_arriving_data(d)
   cl.new_request(request)
 
 
   cl.process_arriving_data(d)
   cl.new_request(request)
 
-def log_http(desca, msg):
+def log_http(desca, msg, **kwargs):
   try:
   try:
-    d = desca['d']
+    kwargs['d'] = desca['d']
     del desca['d']
   except KeyError:
     del desca['d']
   except KeyError:
-    d = None
-  log_debug(DBG.HTTP, msg + repr(desca), d=d)
+    pass
+  log_debug(DBG.HTTP, msg + repr(desca), **kwargs)
 
 class IphttpResource(twisted.web.resource.Resource):
   isLeaf = True
 
 class IphttpResource(twisted.web.resource.Resource):
   isLeaf = True
@@ -181,11 +190,11 @@ class IphttpResource(twisted.web.resource.Resource):
     try: process_request(request, desca)
     except Exception as e:
       emsg = traceback.format_exc()
     try: process_request(request, desca)
     except Exception as e:
       emsg = traceback.format_exc()
-      log_http(desca, 'EXCEPTION ' + emsg)
+      log_http(desca, 'RETURNING EXCEPTION ' + emsg)
       request.setHeader('Content-Type','text/plain; charset="utf-8"')
       request.setResponseCode(400)
       return (emsg + ' # ' + repr(desca) + '\r\n').encode('utf-8')
       request.setHeader('Content-Type','text/plain; charset="utf-8"')
       request.setResponseCode(400)
       return (emsg + ' # ' + repr(desca) + '\r\n').encode('utf-8')
-    log_http(desca, '... [%s]' % id(request))
+    log_debug(DBG.HTTP_CTRL, '...', idof=id(request))
     return NOT_DONE_YET
 
   def render_GET(self, request):
     return NOT_DONE_YET
 
   def render_GET(self, request):
@@ -225,6 +234,6 @@ def process_cfg():
 
 common_startup()
 process_cfg()
 
 common_startup()
 process_cfg()
-start_ipif(c.ipif_command, route)
+start_ipif(c.ipif_command, (lambda p,s,d: route(p,"[ipif]",s,d)))
 start_http()
 common_run()
 start_http()
 common_run()