Commit 7d72c8b0 authored by Sebastien Robin's avatar Sebastien Robin

do not use httplib directly, use urllib2 instead

It is not recommanded to use httplib directly, we should better
use urllib2, then this library will use httplib. This solve
issues with libnetworkcache when we try to use it behind an
http proxy.
parent 000c1580
...@@ -20,6 +20,7 @@ import json ...@@ -20,6 +20,7 @@ import json
import os import os
import tempfile import tempfile
import urllib import urllib
import urllib2
import urlparse import urlparse
...@@ -45,7 +46,7 @@ class NetworkcacheClient(object): ...@@ -45,7 +46,7 @@ class NetworkcacheClient(object):
return_dict['path'] = parsed_url.path return_dict['path'] = parsed_url.path
return_dict['host'] = parsed_url.hostname return_dict['host'] = parsed_url.hostname
return_dict['port'] = parsed_url.port return_dict['port'] = parsed_url.port or 80
return return_dict return return_dict
def __init__(self, shacache, shadir): def __init__(self, shacache, shadir):
...@@ -145,17 +146,13 @@ class NetworkcacheClient(object): ...@@ -145,17 +146,13 @@ class NetworkcacheClient(object):
if directory_key is not None: if directory_key is not None:
path_info = os.path.join(self.shadir_path, directory_key) path_info = os.path.join(self.shadir_path, directory_key)
shadir_connection = httplib.HTTPConnection(self.shadir_host, url = "http://%s:%s%s" % (self.shadir_host, self.shadir_port, path_info)
self.shadir_port) request = urllib2.Request(url=url, data=None,headers=self.shadir_header_dict)
try: try:
shadir_connection.request('GET', path_info, headers=self.shadir_header_dict) result = urllib2.urlopen(request)
result = shadir_connection.getresponse()
data = result.read() data = result.read()
finally: except urllib2.HTTPError, error:
shadir_connection.close() raise DirectoryNotFound("%s : %s" % (error.code, error.msg))
if result.status != 200:
raise DirectoryNotFound(result.read())
data_list = json.loads(data) data_list = json.loads(data)
if len(data_list) > 1: if len(data_list) > 1:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment