S3 - Add RequestId to responses (#3836)
This commit is contained in:
parent
6a6a71ebff
commit
532386327d
@ -8,6 +8,7 @@ import sys
|
|||||||
from botocore.awsrequest import AWSPreparedRequest
|
from botocore.awsrequest import AWSPreparedRequest
|
||||||
|
|
||||||
from moto.core.utils import (
|
from moto.core.utils import (
|
||||||
|
amzn_request_id,
|
||||||
str_to_rfc_1123_datetime,
|
str_to_rfc_1123_datetime,
|
||||||
py2_strip_unicode_keys,
|
py2_strip_unicode_keys,
|
||||||
unix_time_millis,
|
unix_time_millis,
|
||||||
@ -259,6 +260,7 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin):
|
|||||||
# Using path-based buckets
|
# Using path-based buckets
|
||||||
return self.bucket_response(request, full_url, headers)
|
return self.bucket_response(request, full_url, headers)
|
||||||
|
|
||||||
|
@amzn_request_id
|
||||||
def bucket_response(self, request, full_url, headers):
|
def bucket_response(self, request, full_url, headers):
|
||||||
self.method = request.method
|
self.method = request.method
|
||||||
self.path = self._get_path(request)
|
self.path = self._get_path(request)
|
||||||
@ -1026,6 +1028,7 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin):
|
|||||||
line = body_io.readline()
|
line = body_io.readline()
|
||||||
return bytes(new_body)
|
return bytes(new_body)
|
||||||
|
|
||||||
|
@amzn_request_id
|
||||||
def key_or_control_response(self, request, full_url, headers):
|
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 :/
|
# Key and Control are lumped in because splitting out the regex is too much of a pain :/
|
||||||
self.method = request.method
|
self.method = request.method
|
||||||
|
27
tests/test_s3/test_s3_metadata.py
Normal file
27
tests/test_s3/test_s3_metadata.py
Normal file
@ -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"])
|
Loading…
Reference in New Issue
Block a user