'Handle HTTP HEAD requests for the Swift Object Server.'

@public
@timing_stats(sample_rate=0.8)
def HEAD(self, request):

    (device, partition, account, container, obj, policy) = get_name_and_placement(request, 5, 5, True)
    frag_prefs = safe_json_loads(request.headers.get('X-Backend-Fragment-Preferences'))
    try:
        disk_file = self.get_diskfile(device, partition, account, container, obj, policy=policy, frag_prefs=frag_prefs)
    except DiskFileDeviceUnavailable:
        return HTTPInsufficientStorage(drive=device, request=request)
    try:
        metadata = disk_file.read_metadata()
    except DiskFileXattrNotSupported:
        return HTTPInsufficientStorage(drive=device, request=request)
    except (DiskFileNotExist, DiskFileQuarantined) as e:
        headers = {}
        if hasattr(e, 'timestamp'):
            headers['X-Backend-Timestamp'] = e.timestamp.internal
        return HTTPNotFound(request=request, headers=headers, conditional_response=True)
    conditional_etag = resolve_etag_is_at_header(request, metadata)
    response = Response(request=request, conditional_response=True, conditional_etag=conditional_etag)
    response.headers['Content-Type'] = metadata.get('Content-Type', 'application/octet-stream')
    for (key, value) in metadata.items():
        if (is_sys_or_user_meta('object', key) or is_object_transient_sysmeta(key) or (key.lower() in self.allowed_headers)):
            response.headers[key] = value
    response.etag = metadata['ETag']
    ts = Timestamp(metadata['X-Timestamp'])
    response.last_modified = math.ceil(float(ts))
    response.headers['X-Timestamp'] = ts.normal
    response.headers['X-Backend-Timestamp'] = ts.internal
    response.headers['X-Backend-Data-Timestamp'] = disk_file.data_timestamp.internal
    if disk_file.durable_timestamp:
        response.headers['X-Backend-Durable-Timestamp'] = disk_file.durable_timestamp.internal
    response.headers['X-Backend-Fragments'] = _make_backend_fragments_header(disk_file.fragments)
    response.content_length = int(metadata['Content-Length'])
    try:
        response.content_encoding = metadata['Content-Encoding']
    except KeyError:
        pass
    return response
