Core: add date to response metadata (#6329)

This commit is contained in:
rafcio19 2023-05-20 21:47:08 +01:00 committed by GitHub
parent e677bee2e6
commit eeb32bd048
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -306,7 +306,10 @@ class BaseResponse(_TemplateEnvironmentMixin, ActionAuthenticatorMixin):
self.headers = request.headers
if "host" not in self.headers:
self.headers["host"] = urlparse(full_url).netloc
self.response_headers = {"server": "amazon.com"}
self.response_headers = {
"server": "amazon.com",
"date": datetime.datetime.now().strftime("%a, %d %b %Y %H:%M:%S GMT"),
}
# Register visit with IAM
from moto.iam.models import mark_account_as_visited

View File

@ -1,3 +1,4 @@
import datetime
from unittest import SkipTest, mock
import sure # noqa # pylint: disable=unused-import
@ -8,6 +9,7 @@ from botocore.awsrequest import AWSPreparedRequest
from moto.core.responses import AWSServiceSpec, BaseResponse
from moto.core.responses import flatten_json_request_body
from moto import settings
from freezegun import freeze_time
def test_flatten_json_request_body():
@ -225,3 +227,21 @@ def test_jinja_render_prettify(m_env_var):
xml_string = template.render()
assert xml_string == expected_output
assert m_env_var
def test_response_metadata():
# Setup
frozen_time = datetime.datetime(
2023, 5, 20, 10, 20, 30, tzinfo=datetime.timezone.utc
)
request = AWSPreparedRequest("GET", "http://request", {}, None, False)
# Execute
with freeze_time(frozen_time):
bc = BaseResponse()
bc.setup_class(request, request.url, request.headers)
# Verify
assert "date" in bc.response_headers
if not settings.TEST_SERVER_MODE:
assert bc.response_headers["date"] == "Sat, 20 May 2023 10:20:30 GMT"