[Inteproxy-commits] r31 - trunk

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Apr 5 14:52:09 CEST 2007


Author: bh
Date: 2007-04-05 14:52:09 +0200 (Thu, 05 Apr 2007)
New Revision: 31

Modified:
   trunk/ChangeLog
   trunk/transcoder.py
Log:
First step towards http proxy.  InteProxy can be used as a http
proxy now as well (it still supports the old mode at the same
time).  This implements part of feature request #349

* transcoder.py (lookup_transcoder): New method extracted from
get_transcoder to handle the actual transcoder lookup.
(get_transcoder): Handles the case when InteProxy is used as an
HTTP Proxy.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-04-04 18:36:45 UTC (rev 30)
+++ trunk/ChangeLog	2007-04-05 12:52:09 UTC (rev 31)
@@ -1,3 +1,14 @@
+2007-04-05  Bernhard Herzog  <bh at intevation.de>
+
+	First step towards http proxy.  InteProxy can be used as a http
+	proxy now as well (it still supports the old mode at the same
+	time).  This implements part of feature request #349
+
+	* transcoder.py (lookup_transcoder): New method extracted from
+	get_transcoder to handle the actual transcoder lookup.
+	(get_transcoder): Handles the case when InteProxy is used as an
+	HTTP Proxy.
+
 2007-04-04  Bernhard Herzog  <bh at intevation.de>
 
 	* InteProxy.py (run_server): The default value of the debug level

Modified: trunk/transcoder.py
===================================================================
--- trunk/transcoder.py	2007-04-04 18:36:45 UTC (rev 30)
+++ trunk/transcoder.py	2007-04-05 12:52:09 UTC (rev 31)
@@ -122,16 +122,8 @@
 transcoder_map = {
     }
 
-def get_transcoder(method, url):
-    """Return a transcoder for the given HTTP method and URL"""
-    scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
 
-    # both scheme and netloc must be empty strings because the url
-    # we work with is the url on the first line of a HTTP request
-    # which doesn't include them
-    assert scheme == ""
-    assert netloc == ""
-
+def lookup_transcoder(method, path):
     # FIXME: ideally, we would use the IdentityTranscoder by default.
     # However, until we have some way to populate the transcoder_map
     # without hardcoding it, i. e. until we have a configuration file or
@@ -139,15 +131,47 @@
     # OWSProxyGETTranscoder as defaults so that the behavior is
     # basically the same as before the introduction of the transcoders.
     defaults = dict(GET=OWSProxyGETTranscoder, POST=OWSProxyPOSTTranscoder)
-    transcoder_class = transcoder_map.get(path, defaults).get(method,
-                                                           IdentityTranscoder)
+    return transcoder_map.get(path, defaults).get(method, IdentityTranscoder)
 
-    # determine the remote host encoded in the path
-    split_path = path.split("/")
-    if not split_path[0]:
-        del split_path[0]
-    real_netloc = split_path.pop(0)
-    real_path = "/" + "/".join(split_path)
 
+def get_transcoder(method, url):
+    """Return a transcoder for the given HTTP method and URL
+
+    URL should be the URL given for the GET or POST http request.  This
+    function extracts the real remote host from the URL and uses the URL
+    to look up the transcoder with lookup_transcoder.
+
+    This function supports two ways to encode the remote host in the
+    URL:
+
+       -- InteProxy is accessed directly as an HTTP server.  In this
+          cases URL is an absolute pathname and does not include a
+          hostname in the normal URL syntax.  Instead get_transcoder
+          assumes that it encodes the real remote host in the first
+          component of the path.  This is the old InteProxy method
+
+       -- InteProxy is used as a HTTP-proxy.  In this case URL will be a
+          full URL including a hostname.  In this case get_transcoder
+          will use the host of the URL as the real remote host.  The
+          path component of the URL is not modified.
+    """
+    scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
+
+    # If scheme is given, InteProxy is used as a HTTP proxy.
+    if scheme:
+        transcoder_key = netloc + path
+        real_netloc = netloc
+        real_path = path
+    else:
+        transcoder_key = path
+
+        # determine the remote host encoded in the path
+        split_path = path.split("/")
+        if not split_path[0]:
+            del split_path[0]
+        real_netloc = split_path.pop(0)
+        real_path = "/" + "/".join(split_path)
+
+    transcoder_class = lookup_transcoder(method, transcoder_key)
     return transcoder_class(method,
                             ("https", real_netloc, real_path, query, fragment))



More information about the Inteproxy-commits mailing list