import syslog
-import traceback
-
clients = { }
#---------- "router" ----------
log_debug(dflag, ('client %s: ' % self._ip)+msg, **kwargs)
def process_arriving_data(self, d):
- self._log(DBG.FLOW, 'req data', d=d)
+ self._log(DBG.FLOW, "req data (enc'd)", d=d)
if not len(d): return
for packet in slip.decode(d):
(saddr, daddr) = packet_addrs(packet)
raise ValueError('tro must be %d' % cl.target_requests_outstanding)
try:
- d = request.args[b'd']
+ 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)
-def log_http(desca, msg):
+def log_http(desca, msg, **kwargs):
try:
- d = desca['d']
+ kwargs['d'] = desca['d']
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
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')
- log_http(desca, '... [%s]' % id(request))
+ log_debug(DBG.HTTP_CTRL, '...', idof=id(request))
return NOT_DONE_YET
def render_GET(self, request):
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()