From 5b08703fa8338407af063652658e7f570a2ec0f8 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Mon, 30 Jul 2012 11:58:29 +1200 Subject: Handle disconnects on flush. --- libpathod/pathoc.py | 2 ++ libpathod/pathod.py | 26 +++++++++++++------------- libpathod/templates/docs_pathod.html | 10 ++++------ libpathod/test.py | 2 +- 4 files changed, 20 insertions(+), 20 deletions(-) (limited to 'libpathod') diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py index b78d986f..1bc340cd 100644 --- a/libpathod/pathoc.py +++ b/libpathod/pathoc.py @@ -65,6 +65,8 @@ class Pathoc(tcp.TCPClient): return except tcp.NetLibTimeout: print >> fp, "<<", "Timeout" + except tcp.NetLibDisconnect: + print >> fp, "<<", "Disconnect" else: if respdump: print_full(fp, *resp) diff --git a/libpathod/pathod.py b/libpathod/pathod.py index 0ae32c47..7cb7d604 100644 --- a/libpathod/pathod.py +++ b/libpathod/pathod.py @@ -136,17 +136,7 @@ class PathodHandler(tcp.BaseHandler): return while not self.finished: - try: - if not self.handle_request(): - return - except tcp.NetLibDisconnect: # pragma: no cover - self.info("Disconnect") - self.server.add_log( - dict( - type = "error", - msg = "Disconnect" - ) - ) + if not self.handle_request(): return @@ -211,8 +201,18 @@ class Pathod(tcp.TCPServer): def handle_connection(self, request, client_address): h = PathodHandler(request, client_address, self) - h.handle() - h.finish() + try: + h.handle() + h.finish() + except tcp.NetLibDisconnect: # pragma: no cover + h.info("Disconnect") + self.add_log( + dict( + type = "error", + msg = "Disconnect" + ) + ) + return def add_log(self, d): if not self.noapi: diff --git a/libpathod/templates/docs_pathod.html b/libpathod/templates/docs_pathod.html index b5a03023..a581d18d 100644 --- a/libpathod/templates/docs_pathod.html +++ b/libpathod/templates/docs_pathod.html @@ -8,12 +8,10 @@ -

Pathod is a pathological HTTP daemon, designed to let you craft arbitrarily -malevolent HTTP responses. It lets you thoroughly exercise the failure modes of -HTTP clients by creatively violating the standards. HTTP responses are -specified using a small, terse language, which -pathod shares with its evil twin pathoc.

- +

Pathod is a pathological HTTP daemon designed to let you craft almost any +conceivable HTTP response, including ones that creatively violate the +standards. HTTP responses are specified using a small, +terse language, which pathod shares with its evil twin pathoc.