2605N/AProvide for HTTP Range requests in Glance API, and return correct 206
2605N/APartial Content.
2605N/A
4070N/ASee community bugs:
2605N/A https://bugs.launchpad.net/glance/+bug/1399851
2605N/A https://bugs.launchpad.net/glance/+bug/1417069
2605N/A
2605N/A--- glance-2015.1.2/glance/api/v2/image_data.py.~1~ 2015-10-13 09:38:23.000000000 -0700
2605N/A+++ glance-2015.1.2/glance/api/v2/image_data.py 2016-01-19 12:23:11.296863244 -0800
2605N/A@@ -211,6 +211,8 @@ class ResponseSerializer(wsgi.JSONRespon
2605N/A
2605N/A def download(self, response, image):
2605N/A offset, chunk_size = 0, None
2605N/A+
2605N/A+ # Initially attempt to get "Content-Range" request
2605N/A range_val = response.request.get_content_range()
2605N/A
2605N/A if range_val:
2605N/A@@ -222,6 +224,21 @@ class ResponseSerializer(wsgi.JSONRespon
2605N/A if range_val.stop is not None:
2605N/A chunk_size = range_val.stop - offset
2605N/A
2605N/A+ # Return 206 Partial Content
2605N/A+ response.status_int = 206
2605N/A+ else:
2605N/A+ # Try for "Range" request header if ContentRange not present
2605N/A+ range_obj = response.request.get_range()
2605N/A+ if range_obj:
2605N/A+ if range_obj.start is not None:
2605N/A+ offset = range_obj.start
2605N/A+
2605N/A+ if range_obj.end is not None:
4070N/A+ chunk_size = range_obj.end - offset
4070N/A+
4070N/A+ # Return 206 Partial Content
4070N/A+ response.status_int = 206
4070N/A+
2900N/A response.headers['Content-Type'] = 'application/octet-stream'
2900N/A
2900N/A try:
2900N/A@@ -246,7 +263,9 @@ class ResponseSerializer(wsgi.JSONRespon
2900N/A response.headers['Content-MD5'] = image.checksum
4070N/A # NOTE(markwash): "response.app_iter = ..." also erroneously resets the
4070N/A # content-length
4070N/A- response.headers['Content-Length'] = str(image.size)
4070N/A+ # NOTE(mattk): Should be set to chunk_size or image.size
4070N/A+ response.headers['Content-Length'] = \
2900N/A+ str(chunk_size) if chunk_size != 0 else str(image.size)
2900N/A
4507N/A def upload(self, response, result):
2605N/A response.status_int = 204
2605N/A--- glance-2015.1.2/glance/common/wsgi.py.~1~ 2015-10-13 09:38:23.000000000 -0700
2605N/A+++ glance-2015.1.2/glance/common/wsgi.py 2016-01-19 12:23:11.297682604 -0800
2605N/A@@ -752,7 +752,7 @@ class Request(webob.Request):
2605N/A return self.accept_language.best_match(langs)
2605N/A
2605N/A def get_content_range(self):
2605N/A- """Return the `Range` in a request."""
2605N/A+ """Return the `Content-Range` in a request."""
2605N/A range_str = self.headers.get('Content-Range')
2605N/A if range_str is not None:
2605N/A range_ = webob.byterange.ContentRange.parse(range_str)
2605N/A@@ -761,6 +761,16 @@ class Request(webob.Request):
2605N/A raise webob.exc.HTTPBadRequest(explanation=msg)
2605N/A return range_
2605N/A
2605N/A+ def get_range(self):
2605N/A+ """Return the 'Range' in a reqyest."""
2605N/A+ range_str = self.headers.get('Range')
2605N/A+ if range_str is not None:
2605N/A+ range_ = webob.byterange.Range.parse(range_str)
2605N/A+ if range_ is None:
2605N/A+ msg = _('Malformed Range header: %s') % range_str
2605N/A+ raise webob.exc.HTTPBadRequest(explanation=msg)
2605N/A+ return range_
2605N/A+
2605N/A
2605N/A class JSONRequestDeserializer(object):
2605N/A valid_transfer_encoding = frozenset(['chunked', 'compress', 'deflate',
2605N/A