[Inteproxy-commits] r126 - in trunk: . inteproxy

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu May 15 02:25:10 CEST 2008


Author: bernhard
Date: 2008-05-15 02:25:09 +0200 (Thu, 15 May 2008)
New Revision: 126

Modified:
   trunk/ChangeLog
   trunk/inteproxy/proxycore.py
Log:
Changed behaviour: When asked as HTTP 1.0 by the client, we also
ask HTTP 1.0 to the server. This prevents Transfer-Encoding: chunked,
which an HTTP 1.0 might not be able to handle.

* inteproxy/proxycore.py(handle_proxy_request()): Also logging 
the http protocol version of the received request.

* inteproxy/proxycore.py: New classes HTTP10HTTPSConnection
and HTTP10HTTPSHandler used by handle_proxy_request() now when
self.request_version == "HTTP/1.0".


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2008-04-17 14:17:05 UTC (rev 125)
+++ trunk/ChangeLog	2008-05-15 00:25:09 UTC (rev 126)
@@ -1,3 +1,16 @@
+2008-05-15  Bernhard Reiter  <bernhard at intevation.de>
+
+	Changed behaviour: When asked as HTTP 1.0 by the client, we also
+	ask HTTP 1.0 to the server. This prevents Transfer-Encoding: chunked,
+	which an HTTP 1.0 might not be able to handle.
+
+	* inteproxy/proxycore.py(handle_proxy_request()): Also logging 
+	the http protocol version of the received request.
+
+	* inteproxy/proxycore.py: New classes HTTP10HTTPSConnection
+	and HTTP10HTTPSHandler used by handle_proxy_request() now when
+	self.request_version == "HTTP/1.0".
+
 2008-04-17  Jan-Oliver Wagner  <jan-oliver.wagner at intevation.de>
 
 	* Makefile: fix for user name

Modified: trunk/inteproxy/proxycore.py
===================================================================
--- trunk/inteproxy/proxycore.py	2008-04-17 14:17:05 UTC (rev 125)
+++ trunk/inteproxy/proxycore.py	2008-05-15 00:25:09 UTC (rev 126)
@@ -9,6 +9,7 @@
 """The HTTP proxy at the core of InteProxy"""
 
 import sys
+import httplib
 import traceback
 import time
 import urllib2
@@ -31,9 +32,24 @@
         year, hh, mm, ss)
     return s
 
+class HTTP10HTTPSConnection(httplib.HTTPSConnection):
+    """Subclass of httplib.HTTPSConnection to force HTTP 1.0 protocol."""
+    _http_vsn = 10
+    _http_vsn_str = 'HTTP/1.0'
 
+    def __init_(self, host, port=None, key_file=None, cert_file=None,
+                     strict=None):
+        httplib.HTTPSConnection.__init__(self, host, port, key_file, cert_file,
+                        strict)
+
+
+class HTTP10HTTPSHandler(urllib2.HTTPSHandler):
+    """Subclass of HTTPSHandler forcing HTTP 1.0 protocol with httplib."""
+    def https_open(self, req):
+        return self.do_open(HTTP10HTTPSConnection, req)
+
+
 class InteProxyHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
-
     # Whether the SHUTDOWN method is allowed.  If allowed, anybody who can
     # connect to the server can shutdown the server.
     allow_shutdown = False
@@ -74,7 +90,8 @@
     def handle_proxy_request(self):
         """Handle a request that needs to be 'proxied'.
         """
-        self.log_debug("Got %s request for %s", self.command, self.path)
+        self.log_debug("Got %s request for %s, version '%s'",
+                    self.command, self.path, self.request_version)
         for header, value in self.headers.items():
             self.log_debug("header from client: %s:%r", header, value)
 
@@ -139,7 +156,16 @@
         #
         response = None
         try:
-            response = urllib2.urlopen(request)
+            # We need to make sure that urllib2 uses HTTP 1.0 when we
+            # got asked as HTTP 1.0 from the client, so we need to use
+            # derived classes
+            if self.request_version == "HTTP/1.0":
+                self.log_debug("Trying my HTTP10HTTPSHandler.")
+                #FIXME: Do we need more handlers here? Maybe Referer?
+                opener = urllib2.build_opener(HTTP10HTTPSHandler)
+                response = opener.open(request)
+            else:
+                response = urllib2.urlopen(request)
         except urllib2.HTTPError, err:
             # a HTTPError is a valid http response object, so we can
             # treat it like a normal response.



More information about the Inteproxy-commits mailing list