def _process_v2_request(self, request, image_id, image_iterator): # We do some contortions to get the image_metadata so # that we can provide it to 'size_checked_iter' which # will generate a notification. # TODO(mclaren): Make notification happen more # naturally once caching is part of the domain model. db_api = glance.db.get_api() image_repo = glance.db.ImageRepo(request.context, db_api) image = image_repo.get(image_id) image_meta = glance.notifier.format_image_notification(image) self._verify_metadata(image_meta) response = webob.Response(request=request) response.app_iter = size_checked_iter(response, image_meta, image_meta['size'], image_iterator, notifier.Notifier()) # NOTE (flwang): Set the content-type, content-md5 and content-length # explicitly to be consistent with the non-cache scenario. # Besides, it's not worth the candle to invoke the "download" method # of ResponseSerializer under image_data. Because method "download" # will reset the app_iter. Then we have to call method # "size_checked_iter" to avoid missing any notification. But after # call "size_checked_iter", we will lose the content-md5 and # content-length got by the method "download" because of this issue: # https://github.com/Pylons/webob/issues/86 response.headers['Content-Type'] = 'application/octet-stream' response.headers['Content-MD5'] = image.checksum response.headers['Content-Length'] = str(image.size) return response
def download(self, response, result): size = result["meta"]["size"] checksum = result["meta"]["checksum"] response.headers["Content-Length"] = size response.headers["Content-Type"] = "application/octet-stream" if checksum: response.headers["Content-MD5"] = checksum response.app_iter = common.size_checked_iter(response, result["meta"], size, result["data"], self.notifier)
def download(self, response, result): size = result['meta']['size'] checksum = result['meta']['checksum'] response.headers['Content-Length'] = size response.headers['Content-Type'] = 'application/octet-stream' if checksum: response.headers['Content-MD5'] = checksum response.app_iter = common.size_checked_iter( response, result['meta'], size, result['data'], self.notifier)
def download(self, response, result): size = result['meta']['size'] checksum = result['meta']['checksum'] response.headers['Content-Length'] = size response.headers['Content-Type'] = 'application/octet-stream' if checksum: response.headers['Content-MD5'] = checksum response.app_iter = common.size_checked_iter(response, result['meta'], size, result['data'], self.notifier)
def download(self, response, result): size = result['meta']['size'] checksum = result['meta']['checksum'] response.headers['Content-Length'] = size response.headers['Content-Type'] = 'application/octet-stream' response.app_iter = common.size_checked_iter( response, result['meta'], size, result['data'], self.notifier) #NOTE(saschpe): "response.app_iter = ..." currently resets Content-MD5 # (https://github.com/Pylons/webob/issues/86), so it should be set # afterwards for the time being. if checksum: response.headers['Content-MD5'] = checksum
def show(self, response, result): image_meta = result["image_meta"] image_iter = result["image_iterator"] # image_meta['size'] should be an int, but could possibly be a str expected_size = int(image_meta["size"]) response.app_iter = common.size_checked_iter(response, image_meta, expected_size, image_iter, self.notifier) # Using app_iter blanks content-length, so we set it here... response.headers["Content-Length"] = str(image_meta["size"]) response.headers["Content-Type"] = "application/octet-stream" self._inject_image_meta_headers(response, image_meta) self._inject_checksum_header(response, image_meta) return response
def show(self, response, result): image_meta = result['image_meta'] image_iter = result['image_iterator'] # image_meta['size'] should be an int, but could possibly be a str expected_size = int(image_meta['size']) response.app_iter = common.size_checked_iter( response, image_meta, expected_size, image_iter, self.notifier) # Using app_iter blanks content-length, so we set it here... response.headers['Content-Length'] = str(image_meta['size']) response.headers['Content-Type'] = 'application/octet-stream' self._inject_image_meta_headers(response, image_meta) self._inject_checksum_header(response, image_meta) return response
def _process_v2_request(self, request, image_id, image_iterator): # We do some contortions to get the image_metadata so # that we can provide it to 'size_checked_iter' which # will generate a notification. # TODO(mclaren): Make notification happen more # naturally once caching is part of the domain model. db_api = glance.db.get_api() image_repo = glance.db.ImageRepo(request.context, db_api) image = image_repo.get(image_id) image_meta = glance.notifier.format_image_notification(image) self._verify_metadata(image_meta) response = webob.Response(request=request) response.app_iter = size_checked_iter(response, image_meta, image_meta['size'], image_iterator, notifier.Notifier()) return response
def show(self, response, result): image_meta = result['image_meta'] image_id = image_meta['id'] image_iter = result['image_iterator'] # image_meta['size'] is a str expected_size = int(image_meta['size']) response.app_iter = common.size_checked_iter( response, image_meta, expected_size, image_iter, self.notifier) # Using app_iter blanks content-length, so we set it here... response.headers['Content-Length'] = image_meta['size'] response.headers['Content-Type'] = 'application/octet-stream' self._inject_image_meta_headers(response, image_meta) self._inject_location_header(response, image_meta) self._inject_checksum_header(response, image_meta) return response