diff options
Diffstat (limited to 'libpathod')
-rw-r--r-- | libpathod/pathod.py | 36 | ||||
-rw-r--r-- | libpathod/rparse.py | 13 | ||||
-rw-r--r-- | libpathod/utils.py | 25 |
3 files changed, 25 insertions, 49 deletions
diff --git a/libpathod/pathod.py b/libpathod/pathod.py index 8a29b9cb..e0a0764f 100644 --- a/libpathod/pathod.py +++ b/libpathod/pathod.py @@ -18,6 +18,10 @@ class PathodHandler(tcp.BaseHandler): return None method, path, httpversion = protocol.parse_init_http(line) + headers = odict.ODictCaseless(protocol.read_headers(self.rfile)) + content = protocol.read_http_body_request( + self.rfile, self.wfile, headers, httpversion, None + ) if path.startswith(self.server.prefix): spec = urllib.unquote(path)[len(self.server.prefix):] try: @@ -27,24 +31,20 @@ class PathodHandler(tcp.BaseHandler): 800, "Error parsing response spec: %s\n"%v.msg + v.marked() ) - presp.serve(self.wfile) - self.finish() - return - - headers = odict.ODictCaseless(protocol.read_headers(self.rfile)) - content = protocol.read_http_body_request( - self.rfile, self.wfile, headers, httpversion, None - ) - cc = wsgi.ClientConn(self.client_address) - req = wsgi.Request(cc, "http", method, path, headers, content) - sn = self.connection.getsockname() - app = wsgi.WSGIAdaptor( - self.server.app, - sn[0], - self.server.port, - version.NAMEVERSION - ) - app.serve(req, self.wfile) + ret = presp.serve(self.wfile) + if ret["disconnect"]: + self.close() + else: + cc = wsgi.ClientConn(self.client_address) + req = wsgi.Request(cc, "http", method, path, headers, content) + sn = self.connection.getsockname() + app = wsgi.WSGIAdaptor( + self.server.app, + sn[0], + self.server.port, + version.NAMEVERSION + ) + app.serve(req, self.wfile) class Pathod(tcp.TCPServer): diff --git a/libpathod/rparse.py b/libpathod/rparse.py index 677c6b54..47084520 100644 --- a/libpathod/rparse.py +++ b/libpathod/rparse.py @@ -390,6 +390,9 @@ class Response: return ret def write_values(self, fp, vals, actions, sofar=0, skip=0, blocksize=BLOCKSIZE): + """ + Return True if connection should disconnect. + """ while vals: part = vals.pop() for i in range(skip, len(part), blocksize): @@ -401,18 +404,15 @@ class Response: if p[1] == "pause": fp.write(d[:offset]) time.sleep(p[2]) - self.write_values( + return self.write_values( fp, vals, actions, sofar=sofar+offset, skip=i+offset, blocksize=blocksize ) - return elif p[1] == "disconnect": fp.write(d[:offset]) - fp.finish() - fp.connection.stream.close() - return + return True fp.write(d) sofar += len(d) skip = 0 @@ -447,9 +447,10 @@ class Response: vals.reverse() actions = self.ready_actions(self.length(), self.actions) actions.reverse() - self.write_values(fp, vals, actions[:]) + disconnect = self.write_values(fp, vals, actions[:]) duration = time.time() - started return dict( + disconnect = disconnect, started = started, duration = duration, actions = actions, diff --git a/libpathod/utils.py b/libpathod/utils.py index 0e3bda9d..f421b8a6 100644 --- a/libpathod/utils.py +++ b/libpathod/utils.py @@ -4,31 +4,6 @@ import rparse class AnchorError(Exception): pass -class Sponge: - def __getattr__(self, x): - return Sponge() - - def __call__(self, *args, **kwargs): - pass - - -class DummyRequest: - connection = Sponge() - def __init__(self): - self.buf = [] - - def write(self, d, callback=None): - self.buf.append(str(d)) - if callback: - callback() - - def getvalue(self): - return "".join(self.buf) - - def finish(self): - return - - def parse_anchor_spec(s, settings): """ For now, this is very simple, and you can't have an '=' in your regular |