Revision 4ab1af1a snf-common/synnefo/lib/astakos.py
b/snf-common/synnefo/lib/astakos.py | ||
---|---|---|
37 | 37 |
from urllib import unquote |
38 | 38 |
from django.utils import simplejson as json |
39 | 39 |
|
40 |
from synnefo.lib.pool.http import get_http_connection
|
|
40 |
from synnefo.lib.pool.http import PooledHTTPConnection
|
|
41 | 41 |
|
42 | 42 |
logger = logging.getLogger(__name__) |
43 | 43 |
|
... | ... | |
78 | 78 |
'application/octet-stream') |
79 | 79 |
kwargs['headers'].setdefault('content-length', len(body) if body else 0) |
80 | 80 |
|
81 |
conn = get_http_connection(p.netloc, p.scheme) |
|
82 |
try: |
|
81 |
with PooledHTTPConnection(p.netloc, p.scheme) as conn: |
|
83 | 82 |
conn.request(method, p.path + '?' + p.query, **kwargs) |
84 | 83 |
response = conn.getresponse() |
85 | 84 |
headers = response.getheaders() |
... | ... | |
87 | 86 |
length = response.getheader('content-length', None) |
88 | 87 |
data = response.read(length) |
89 | 88 |
status = int(response.status) |
90 |
finally: |
|
91 |
conn.close() |
|
92 | 89 |
|
93 | 90 |
if status < 200 or status >= 300: |
94 | 91 |
raise Exception(data, status) |
Also available in: Unified diff