Example #1
0
 def GET(self, request):
     """Handle HTTP GET requests for the Swift Object Server."""
     device, partition, account, container, obj = \
         split_and_validate_path(request, 5, 5, True)
     try:
         disk_file = self._diskfile(device,
                                    partition,
                                    account,
                                    container,
                                    obj,
                                    keep_data_fp=True,
                                    iter_hook=sleep)
     except DiskFileDeviceUnavailable:
         return HTTPInsufficientStorage(drive=device, request=request)
     if disk_file.is_deleted() or disk_file.is_expired():
         if request.headers.get('if-match') == '*':
             return HTTPPreconditionFailed(request=request)
         else:
             return HTTPNotFound(request=request)
     try:
         file_size = disk_file.get_data_file_size()
     except (DiskFileError, DiskFileNotExist):
         disk_file.quarantine()
         return HTTPNotFound(request=request)
     if request.headers.get('if-match') not in (None, '*') and \
             disk_file.metadata['ETag'] not in request.if_match:
         disk_file.close()
         return HTTPPreconditionFailed(request=request)
     if request.headers.get('if-none-match') is not None:
         if disk_file.metadata['ETag'] in request.if_none_match:
             resp = HTTPNotModified(request=request)
             resp.etag = disk_file.metadata['ETag']
             disk_file.close()
             return resp
     try:
         if_unmodified_since = request.if_unmodified_since
     except (OverflowError, ValueError):
         # catches timestamps before the epoch
         return HTTPPreconditionFailed(request=request)
     if if_unmodified_since and \
             datetime.fromtimestamp(
                 float(disk_file.metadata['X-Timestamp']), UTC) > \
             if_unmodified_since:
         disk_file.close()
         return HTTPPreconditionFailed(request=request)
     try:
         if_modified_since = request.if_modified_since
     except (OverflowError, ValueError):
         # catches timestamps before the epoch
         return HTTPPreconditionFailed(request=request)
     if if_modified_since and \
             datetime.fromtimestamp(
                 float(disk_file.metadata['X-Timestamp']), UTC) < \
             if_modified_since:
         disk_file.close()
         return HTTPNotModified(request=request)
     response = Response(app_iter=disk_file,
                         request=request,
                         conditional_response=True)
     response.headers['Content-Type'] = disk_file.metadata.get(
         'Content-Type', 'application/octet-stream')
     for key, value in disk_file.metadata.iteritems():
         if key.lower().startswith('x-object-meta-') or \
                 key.lower() in self.allowed_headers:
             response.headers[key] = value
     response.etag = disk_file.metadata['ETag']
     response.last_modified = float(disk_file.metadata['X-Timestamp'])
     response.content_length = file_size
     if response.content_length < self.keep_cache_size and \
             (self.keep_cache_private or
              ('X-Auth-Token' not in request.headers and
               'X-Storage-Token' not in request.headers)):
         disk_file.keep_cache = True
     if 'Content-Encoding' in disk_file.metadata:
         response.content_encoding = disk_file.metadata['Content-Encoding']
     response.headers['X-Timestamp'] = disk_file.metadata['X-Timestamp']
     return request.get_response(response)
Example #2
0
 def GET(self, request):
     """Handle HTTP GET requests for the Swift Object Server."""
     device, partition, account, container, obj = \
         split_and_validate_path(request, 5, 5, True)
     keep_cache = self.keep_cache_private or (
         'X-Auth-Token' not in request.headers and
         'X-Storage-Token' not in request.headers)
     try:
         disk_file = self.get_diskfile(
             device, partition, account, container, obj)
     except DiskFileDeviceUnavailable:
         return HTTPInsufficientStorage(drive=device, request=request)
     try:
         with disk_file.open():
             metadata = disk_file.get_metadata()
             obj_size = int(metadata['Content-Length'])
             if request.headers.get('if-match') not in (None, '*') and \
                     metadata['ETag'] not in request.if_match:
                 return HTTPPreconditionFailed(request=request)
             if request.headers.get('if-none-match') is not None:
                 if metadata['ETag'] in request.if_none_match:
                     resp = HTTPNotModified(request=request)
                     resp.etag = metadata['ETag']
                     return resp
             file_x_ts = metadata['X-Timestamp']
             file_x_ts_flt = float(file_x_ts)
             try:
                 if_unmodified_since = request.if_unmodified_since
             except (OverflowError, ValueError):
                 # catches timestamps before the epoch
                 return HTTPPreconditionFailed(request=request)
             file_x_ts_utc = datetime.fromtimestamp(file_x_ts_flt, UTC)
             if if_unmodified_since and file_x_ts_utc > if_unmodified_since:
                 return HTTPPreconditionFailed(request=request)
             try:
                 if_modified_since = request.if_modified_since
             except (OverflowError, ValueError):
                 # catches timestamps before the epoch
                 return HTTPPreconditionFailed(request=request)
             if if_modified_since and file_x_ts_utc < if_modified_since:
                 return HTTPNotModified(request=request)
             keep_cache = (self.keep_cache_private or
                           ('X-Auth-Token' not in request.headers and
                            'X-Storage-Token' not in request.headers))
             response = Response(
                 app_iter=disk_file.reader(keep_cache=keep_cache),
                 request=request, conditional_response=True)
             response.headers['Content-Type'] = metadata.get(
                 'Content-Type', 'application/octet-stream')
             for key, value in metadata.iteritems():
                 if key.lower().startswith('x-object-meta-') or \
                         key.lower() in self.allowed_headers:
                     response.headers[key] = value
             response.etag = metadata['ETag']
             response.last_modified = file_x_ts_flt
             response.content_length = obj_size
             try:
                 response.content_encoding = metadata[
                     'Content-Encoding']
             except KeyError:
                 pass
             response.headers['X-Timestamp'] = file_x_ts
             resp = request.get_response(response)
     except DiskFileNotExist:
         if request.headers.get('if-match') == '*':
             resp = HTTPPreconditionFailed(request=request)
         else:
             resp = HTTPNotFound(request=request)
     except DiskFileQuarantined:
         resp = HTTPNotFound(request=request)
     return resp
Example #3
0
 def GET(self, request):
     """Handle HTTP GET requests for the Swift Object Server."""
     device, partition, account, container, obj = \
         split_and_validate_path(request, 5, 5, True)
     keep_cache = self.keep_cache_private or (
         'X-Auth-Token' not in request.headers and
         'X-Storage-Token' not in request.headers)
     try:
         disk_file = self.get_diskfile(
             device, partition, account, container, obj)
     except DiskFileDeviceUnavailable:
         return HTTPInsufficientStorage(drive=device, request=request)
     try:
         with disk_file.open():
             metadata = disk_file.get_metadata()
             obj_size = int(metadata['Content-Length'])
             if request.headers.get('if-match') not in (None, '*') and \
                     metadata['ETag'] not in request.if_match:
                 return HTTPPreconditionFailed(request=request)
             if request.headers.get('if-none-match') is not None:
                 if metadata['ETag'] in request.if_none_match:
                     resp = HTTPNotModified(request=request)
                     resp.etag = metadata['ETag']
                     return resp
             file_x_ts = metadata['X-Timestamp']
             file_x_ts_flt = float(file_x_ts)
             try:
                 if_unmodified_since = request.if_unmodified_since
             except (OverflowError, ValueError):
                 # catches timestamps before the epoch
                 return HTTPPreconditionFailed(request=request)
             file_x_ts_utc = datetime.fromtimestamp(file_x_ts_flt, UTC)
             if if_unmodified_since and file_x_ts_utc > if_unmodified_since:
                 return HTTPPreconditionFailed(request=request)
             try:
                 if_modified_since = request.if_modified_since
             except (OverflowError, ValueError):
                 # catches timestamps before the epoch
                 return HTTPPreconditionFailed(request=request)
             if if_modified_since and file_x_ts_utc <= if_modified_since:
                 return HTTPNotModified(request=request)
             keep_cache = (self.keep_cache_private or
                           ('X-Auth-Token' not in request.headers and
                            'X-Storage-Token' not in request.headers))
             response = Response(
                 app_iter=disk_file.reader(keep_cache=keep_cache),
                 request=request, conditional_response=True)
             response.headers['Content-Type'] = metadata.get(
                 'Content-Type', 'application/octet-stream')
             for key, value in metadata.iteritems():
                 if is_user_meta('object', key) or \
                         key.lower() in self.allowed_headers:
                     response.headers[key] = value
             response.etag = metadata['ETag']
             response.last_modified = math.ceil(file_x_ts_flt)
             response.content_length = obj_size
             try:
                 response.content_encoding = metadata[
                     'Content-Encoding']
             except KeyError:
                 pass
             response.headers['X-Timestamp'] = file_x_ts
             resp = request.get_response(response)
     except DiskFileNotExist:
         if request.headers.get('if-match') == '*':
             resp = HTTPPreconditionFailed(request=request)
         else:
             resp = HTTPNotFound(request=request)
     except DiskFileQuarantined:
         resp = HTTPNotFound(request=request)
     return resp
Example #4
0
 def GET(self, request):
     """Handle HTTP GET requests for the Swift Object Server."""
     device, partition, account, container, obj = \
         split_and_validate_path(request, 5, 5, True)
     try:
         disk_file = self._diskfile(device, partition, account, container,
                                    obj, iter_hook=sleep)
     except DiskFileDeviceUnavailable:
         return HTTPInsufficientStorage(drive=device, request=request)
     disk_file.open()
     if disk_file.is_deleted() or disk_file.is_expired():
         if request.headers.get('if-match') == '*':
             return HTTPPreconditionFailed(request=request)
         else:
             return HTTPNotFound(request=request)
     try:
         file_size = disk_file.get_data_file_size()
     except (DiskFileError, DiskFileNotExist):
         disk_file.quarantine()
         return HTTPNotFound(request=request)
     metadata = disk_file.get_metadata()
     if request.headers.get('if-match') not in (None, '*') and \
             metadata['ETag'] not in request.if_match:
         disk_file.close()
         return HTTPPreconditionFailed(request=request)
     if request.headers.get('if-none-match') is not None:
         if metadata['ETag'] in request.if_none_match:
             resp = HTTPNotModified(request=request)
             resp.etag = metadata['ETag']
             disk_file.close()
             return resp
     try:
         if_unmodified_since = request.if_unmodified_since
     except (OverflowError, ValueError):
         # catches timestamps before the epoch
         return HTTPPreconditionFailed(request=request)
     if if_unmodified_since and \
             datetime.fromtimestamp(
                 float(metadata['X-Timestamp']), UTC) > \
             if_unmodified_since:
         disk_file.close()
         return HTTPPreconditionFailed(request=request)
     try:
         if_modified_since = request.if_modified_since
     except (OverflowError, ValueError):
         # catches timestamps before the epoch
         return HTTPPreconditionFailed(request=request)
     if if_modified_since and \
             datetime.fromtimestamp(
                 float(metadata['X-Timestamp']), UTC) < \
             if_modified_since:
         disk_file.close()
         return HTTPNotModified(request=request)
     response = Response(app_iter=disk_file,
                         request=request, conditional_response=True)
     response.headers['Content-Type'] = metadata.get(
         'Content-Type', 'application/octet-stream')
     for key, value in metadata.iteritems():
         if key.lower().startswith('x-object-meta-') or \
                 key.lower() in self.allowed_headers:
             response.headers[key] = value
     response.etag = metadata['ETag']
     response.last_modified = float(metadata['X-Timestamp'])
     response.content_length = file_size
     if response.content_length < self.keep_cache_size and \
             (self.keep_cache_private or
              ('X-Auth-Token' not in request.headers and
               'X-Storage-Token' not in request.headers)):
         disk_file.keep_cache = True
     if 'Content-Encoding' in metadata:
         response.content_encoding = metadata['Content-Encoding']
     response.headers['X-Timestamp'] = metadata['X-Timestamp']
     return request.get_response(response)
Example #5
0
 def GET(self, request):
     """Handle HTTP GET requests for the Swift Object Server."""
     device, partition, account, container, obj = split_and_validate_path(request, 5, 5, True)
     try:
         disk_file = self._diskfile(device, partition, account, container, obj, keep_data_fp=True, iter_hook=sleep)
     except DiskFileDeviceUnavailable:
         return HTTPInsufficientStorage(drive=device, request=request)
     if disk_file.is_deleted() or disk_file.is_expired():
         if request.headers.get("if-match") == "*":
             return HTTPPreconditionFailed(request=request)
         else:
             return HTTPNotFound(request=request)
     try:
         file_size = disk_file.get_data_file_size()
     except (DiskFileError, DiskFileNotExist):
         disk_file.quarantine()
         return HTTPNotFound(request=request)
     if request.headers.get("if-match") not in (None, "*") and disk_file.metadata["ETag"] not in request.if_match:
         disk_file.close()
         return HTTPPreconditionFailed(request=request)
     if request.headers.get("if-none-match") is not None:
         if disk_file.metadata["ETag"] in request.if_none_match:
             resp = HTTPNotModified(request=request)
             resp.etag = disk_file.metadata["ETag"]
             disk_file.close()
             return resp
     try:
         if_unmodified_since = request.if_unmodified_since
     except (OverflowError, ValueError):
         # catches timestamps before the epoch
         return HTTPPreconditionFailed(request=request)
     if (
         if_unmodified_since
         and datetime.fromtimestamp(float(disk_file.metadata["X-Timestamp"]), UTC) > if_unmodified_since
     ):
         disk_file.close()
         return HTTPPreconditionFailed(request=request)
     try:
         if_modified_since = request.if_modified_since
     except (OverflowError, ValueError):
         # catches timestamps before the epoch
         return HTTPPreconditionFailed(request=request)
     if (
         if_modified_since
         and datetime.fromtimestamp(float(disk_file.metadata["X-Timestamp"]), UTC) < if_modified_since
     ):
         disk_file.close()
         return HTTPNotModified(request=request)
     response = Response(app_iter=disk_file, request=request, conditional_response=True)
     response.headers["Content-Type"] = disk_file.metadata.get("Content-Type", "application/octet-stream")
     for key, value in disk_file.metadata.iteritems():
         if key.lower().startswith("x-object-meta-") or key.lower() in self.allowed_headers:
             response.headers[key] = value
     response.etag = disk_file.metadata["ETag"]
     response.last_modified = float(disk_file.metadata["X-Timestamp"])
     response.content_length = file_size
     if response.content_length < self.keep_cache_size and (
         self.keep_cache_private
         or ("X-Auth-Token" not in request.headers and "X-Storage-Token" not in request.headers)
     ):
         disk_file.keep_cache = True
     if "Content-Encoding" in disk_file.metadata:
         response.content_encoding = disk_file.metadata["Content-Encoding"]
     response.headers["X-Timestamp"] = disk_file.metadata["X-Timestamp"]
     return request.get_response(response)