From 3886ccae9379d065e54e0eb7e961992ff3c0ee62 Mon Sep 17 00:00:00 2001
From: Aldo Cortesi
Date: Sat, 5 Jan 2013 15:25:09 +1300
Subject: Provisional proxy mode support for pathod.
---
libpathod/pathod.py | 21 ++++++++++++++++-----
libpathod/templates/docs_pathod.html | 16 ++++++++++++++++
libpathod/test.py | 1 +
libpathod/utils.py | 13 +++++++++++++
pathod | 30 ++++++++++++++++++++----------
test/test_test.py | 1 +
test/test_utils.py | 10 ++++++++++
7 files changed, 77 insertions(+), 15 deletions(-)
diff --git a/libpathod/pathod.py b/libpathod/pathod.py
index d52af15b..587e51bf 100644
--- a/libpathod/pathod.py
+++ b/libpathod/pathod.py
@@ -1,7 +1,7 @@
import urllib, threading, re, logging, socket, sys, base64
from netlib import tcp, http, odict, wsgi
import netlib.utils
-import version, app, language
+import version, app, language, utils
logger = logging.getLogger('pathod')
@@ -54,13 +54,24 @@ class PathodHandler(tcp.BaseHandler):
# Normal termination
return False, None
- parts = http.parse_init_http(line)
- if not parts:
+ m = utils.MemBool()
+ if m(http.parse_init_connect(line)):
+ self.wfile.write(
+ 'HTTP/1.1 200 Connection established\r\n' +
+ ('Proxy-agent: %s\r\n'%version.NAMEVERSION) +
+ '\r\n'
+ )
+ self.wfile.flush()
+
+ if m(http.parse_init_proxy(line)):
+ method, _, _, _, path, httpversion = m.v
+ elif m(http.parse_init_http(line)):
+ method, path, httpversion = m.v
+ else:
s = "Invalid first line: %s"%repr(line)
self.info(s)
return False, dict(type = "error", msg = s)
- method, path, httpversion = parts
headers = http.read_headers(self.rfile)
if headers is None:
s = "Invalid headers"
@@ -133,7 +144,7 @@ class PathodHandler(tcp.BaseHandler):
self.info("\n".join(s))
def handle(self):
- if self.server.ssloptions:
+ if self.server.ssloptions and not self.server.ssloptions["ssl_after_connect"]:
try:
self.convert_to_ssl(
self.server.ssloptions["certfile"],
diff --git a/libpathod/templates/docs_pathod.html b/libpathod/templates/docs_pathod.html
index 8b345d71..42459352 100644
--- a/libpathod/templates/docs_pathod.html
+++ b/libpathod/templates/docs_pathod.html
@@ -45,6 +45,22 @@ those, use the command-line help:
+
+
+
+Pathod automatically responds to both straight HTTP and proxy requests. For
+proxy requests, the upstream host is ignored, and the path portion of the URL
+is used to match anchors. This lets you test software that supports a proxy
+configuration by spoofing responses from upstream servers.
+
+Proxy mode operates even when Pathod is run in SSL mode, but we do not
+support nested SSL connections. This means that CONNECT requests will cause an
+error response.
+
+
+