source: TI12-security/trunk/python/ndg.security.common/ndg/security/common/zsi_utils/httpproxy.py @ 3914

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/ndg.security.common/ndg/security/common/zsi_utils/httpproxy.py@3914
Revision 3914, 2.3 KB checked in by pjkersha, 12 years ago (diff)
  • New ndg.security.common.zsi_util.httpproxy.ProxyHTTPConnection class replaces urllib2client - easier to fit into existing ZSI client framework.
  • Further OpenID integration into Single Sign On Service. User now authenticates OK but patches needed to AuthKit? + need to handle return_to URL dynamically according to page visited before WAYF call.
Line 
1"""Replacement for httplib.HTTPConnection to enable ZSI clients to reach
2remote services through a local HTTP Proxy
3
4Adapted from pywebsvcs mailings March/April '08
5
6NERC Data Grid Project
7"""
8__author__ = "P J Kershaw"
9__date__ = "20/05/08"
10__copyright__ = "(C) 2008 STFC & NERC"
11__license__ = \
12"""This software may be distributed under the terms of the Q Public
13License, version 1.0 or later."""
14__contact__ = "P.J.Kershaw@rl.ac.uk"
15__revision__ = '$Id$'
16import httplib, os
17import urlparse
18
19class ProxyHTTPConnection(httplib.HTTPConnection):
20    '''Replacement for httplib.HTTPConnection to enable ZSI clients to reach
21    remote services through a local HTTP Proxy.
22   
23    Adapted from pywebsvcs mailings March/April '08'''
24   
25    def __init__(self, *arg, **kw):
26        '''
27        @type host: string
28        @param host: hostname (+ port) e.g. localhost:8080
29        @type httpProxyHost: string
30        @param httpProxyHost: hostname of HTTP Proxy defaults to http_proxy
31        environment variable or None if ignoreHttpProxyEnv is set
32        @type ignoreHttpProxyEnv: bool
33        @param ignoreHttpProxyEnv: set to True to ignore any http_proxy
34        environment variable setting. 
35        '''
36        ignoreHttpProxyEnv = kw.get('ignoreHttpProxyEnv', False)
37        if ignoreHttpProxyEnv:
38            httpProxyHostEnv = None
39        else:
40            # Pick-up environment variable and strip protocol prefix
41            httpProxyHostEnv = \
42                os.environ.get('http_proxy', '').replace('http://', '')
43
44        self.connectTo = kw.get('httpProxyHost') or httpProxyHostEnv or arg[0]
45        self.targetHost = arg[0]
46
47        try:
48            del kw['httpProxyHost']
49        except KeyError:
50            pass
51       
52        try:
53            del kw['ignoreHttpProxyEnv']
54        except KeyError:
55            pass
56
57        httplib.HTTPConnection.__init__(self, self.connectTo, **kw)
58
59    def putrequest(self, method, url, **kw):
60       
61        if self.connectTo != self.targetHost:
62            scheme,netloc,path,nil,nil,nil = urlparse.urlparse(url)
63            scheme = scheme or 'http'
64            netloc = netloc or self.targetHost
65            uri = scheme + '://' + netloc + path
66        else :
67            uri = url
68
69        httplib.HTTPConnection.putrequest(self, method, uri, **kw)
Note: See TracBrowser for help on using the repository browser.