|
26 | 26 | try: |
27 | 27 | from http.client import BadStatusLine, HTTPConnection, HTTPSConnection |
28 | 28 | except ImportError: |
| 29 | + print "Getting it from httplib" |
29 | 30 | from httplib import BadStatusLine, HTTPConnection, HTTPSConnection |
30 | 31 |
|
31 | 32 | try: |
@@ -85,6 +86,7 @@ def __init__(self, *a, **k): |
85 | 86 |
|
86 | 87 | class HTTPSConnection(TimeoutMixin, _HTTPSConnection): |
87 | 88 | def __init__(self, *a, **k): |
| 89 | + print "this is the https version" |
88 | 90 | timeout = k.pop('timeout', None) |
89 | 91 | _HTTPSConnection.__init__(self, *a, **k) |
90 | 92 | self.timeout = timeout |
@@ -267,6 +269,7 @@ def __init__(self, cache=None, timeout=None, max_redirects=5, |
267 | 269 | self.connection_pool = ConnectionPool(timeout) |
268 | 270 | self.retry_delays = list(retry_delays) # We don't want this changing on us. |
269 | 271 | self.retryable_errors = set(retryable_errors) |
| 272 | + self.cookie_items={} |
270 | 273 |
|
271 | 274 | def request(self, method, url, body=None, headers=None, credentials=None, |
272 | 275 | num_redirects=0): |
@@ -303,6 +306,22 @@ def request(self, method, url, body=None, headers=None, credentials=None, |
303 | 306 | if authorization: |
304 | 307 | headers['Authorization'] = authorization |
305 | 308 |
|
| 309 | + if not self.cookie_items and 'https' in url: |
| 310 | + import os |
| 311 | + print "Fetching sso cookies" |
| 312 | + cookies = filter(None,open('%s/private/ct-cookie.txt'%(os.getenv('HOME'))).read().split('\n')) |
| 313 | + for c in cookies: |
| 314 | + for key in ['_shibsession','_saml_idp']: |
| 315 | + if key in c: |
| 316 | + rekey=filter(lambda w : w.startswith(key), c.split())[0] |
| 317 | + item=c.split()[ c.split().index( rekey )+1] |
| 318 | + self.cookie_items[rekey] =item |
| 319 | + import pprint |
| 320 | + pprint.pprint( self.cookie_items) |
| 321 | + if self.cookie_items: |
| 322 | + headers.update({"Cookie": '; '.join(map(lambda (k,v) : "%s=%s"%(k,v), self.cookie_items.items()))}) |
| 323 | + |
| 324 | + |
306 | 325 | path_query = util.urlunsplit(('', '') + util.urlsplit(url)[2:4] + ('',)) |
307 | 326 | conn = self.connection_pool.get(url) |
308 | 327 |
|
@@ -498,7 +517,10 @@ def get(self, url): |
498 | 517 | cls = HTTPSConnection |
499 | 518 | else: |
500 | 519 | raise ValueError('%s is not a supported scheme' % scheme) |
| 520 | + #print "We have selected a",cls,"from"#,cls.__class__ |
501 | 521 | conn = cls(host, timeout=self.timeout) |
| 522 | + #import cookielib |
| 523 | + #cf = cookielib.FileCookieJar('/afs/cern.ch/user/v/vlimant/private/ct-cookie.txt') |
502 | 524 | conn.connect() |
503 | 525 |
|
504 | 526 | return conn |
|
0 commit comments