diff --git a/moto/s3/responses.py b/moto/s3/responses.py index 43e27a815..dbc6bf28f 100644 --- a/moto/s3/responses.py +++ b/moto/s3/responses.py @@ -484,7 +484,7 @@ class ResponseObject(_TemplateEnvironmentMixin): elif method == 'PUT': return self._key_response_put(request, body, bucket_name, query, key_name, headers) elif method == 'HEAD': - return self._key_response_head(bucket_name, query, key_name, headers) + return self._key_response_head(bucket_name, query, key_name, headers=request.headers) elif method == 'DELETE': return self._key_response_delete(bucket_name, query, key_name, headers) elif method == 'POST': @@ -597,7 +597,7 @@ class ResponseObject(_TemplateEnvironmentMixin): response_headers = {} version_id = query.get('versionId', [None])[0] - if_modified_since = headers.get('if-modified-since', None) + if_modified_since = headers.get('If-Modified-Since', None) if if_modified_since: if_modified_since = str_to_rfc_1123_datetime(if_modified_since) diff --git a/tests/test_s3/test_s3.py b/tests/test_s3/test_s3.py index 6af653f9e..cd1c2e43e 100644 --- a/tests/test_s3/test_s3.py +++ b/tests/test_s3/test_s3.py @@ -1277,18 +1277,17 @@ def test_boto3_head_object_if_modified_since(): key = 'hello.txt' - with freeze_time(datetime.datetime.now() - datetime.timedelta(hours=3)): - s3.put_object( - Bucket=bucket_name, - Key=key, - Body='test' - ) + s3.put_object( + Bucket=bucket_name, + Key=key, + Body='test' + ) with assert_raises(botocore.exceptions.ClientError) as err: s3.head_object( Bucket=bucket_name, Key=key, - IfModifiedSince=datetime.datetime.now() - datetime.timedelta(hours=2) + IfModifiedSince=datetime.datetime.utcnow() + datetime.timedelta(hours=1) ) e = err.exception e.response['Error'].should.equal({'Code': '304', 'Message': 'Not Modified'})