Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3 - Add RequestId to responses #3836

Merged
merged 1 commit into from
Aug 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions moto/s3/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from botocore.awsrequest import AWSPreparedRequest

from moto.core.utils import (
amzn_request_id,
str_to_rfc_1123_datetime,
py2_strip_unicode_keys,
unix_time_millis,
Expand Down Expand Up @@ -258,6 +259,7 @@ def ambiguous_response(self, request, full_url, headers):
# Using path-based buckets
return self.bucket_response(request, full_url, headers)

@amzn_request_id
def bucket_response(self, request, full_url, headers):
self.method = request.method
self.path = self._get_path(request)
Expand Down Expand Up @@ -1025,6 +1027,7 @@ def _handle_v4_chunk_signatures(self, body, content_length):
line = body_io.readline()
return bytes(new_body)

@amzn_request_id
def key_or_control_response(self, request, full_url, headers):
# Key and Control are lumped in because splitting out the regex is too much of a pain :/
self.method = request.method
Expand Down
27 changes: 27 additions & 0 deletions tests/test_s3/test_s3_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import boto3

from moto import mock_s3
from moto.s3.responses import DEFAULT_REGION_NAME

import sure # noqa


@mock_s3
def test_s3_returns_requestid():
s3 = boto3.client("s3", region_name=DEFAULT_REGION_NAME)
resp = s3.create_bucket(Bucket="mybucket")
_check_metadata(resp)

resp = s3.put_object(Bucket="mybucket", Key="steve", Body=b"is awesome")
_check_metadata(resp)

resp = s3.get_object(Bucket="mybucket", Key="steve")
_check_metadata(resp)


def _check_metadata(resp):
meta = resp["ResponseMetadata"]
headers = meta["HTTPHeaders"]
meta.should.have.key("RequestId")
headers.should.have.key("x-amzn-requestid")
meta["RequestId"].should.equal(headers["x-amzn-requestid"])