Skip to content

Commit

Permalink
Merge "Fixes LP Bug #804429"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Sep 19, 2011
2 parents 5f14075 + 7ce40a7 commit 6c60376
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions glance/store/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,19 @@ def parse_uri(self, uri):
self.path = path


def http_response_iterator(f, size):
def http_response_iterator(conn, size):
"""
Return an iterator for a file-like object
Return an iterator for a file-like object.
:param conn: HTTP(S) Connection
:param size: Chunk size to iterate with
"""
chunk = f.read(size)
response = conn.getresponse()
chunk = response.read(size)
while chunk:
yield chunk
chunk = f.read(size)
chunk = response.read(size)
conn.close()


class Store(glance.store.base.Store):
Expand All @@ -115,10 +120,7 @@ def get(self, location):
conn = conn_class(loc.netloc)
conn.request("GET", loc.path, "", {})

try:
return http_response_iterator(conn.getresponse(), self.CHUNKSIZE)
finally:
conn.close()
return http_response_iterator(conn, self.CHUNKSIZE)

def _get_conn_class(self, loc):
"""
Expand Down

0 comments on commit 6c60376

Please sign in to comment.