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

Adds raw_header to MockRawResponse #6228

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 15 additions & 2 deletions moto/core/botocore_stubber.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@


class MockRawResponse(BytesIO):
def __init__(self, response_input: Union[str, bytes]):
def __init__(self, response_input: Union[str, bytes], headers: Dict[Any, Any]):
self.headers = headers
if isinstance(response_input, str):
response_input = response_input.encode("utf-8")
super().__init__(response_input)
Expand All @@ -18,6 +19,17 @@ def stream(self, **kwargs: Any) -> Any: # pylint: disable=unused-argument
yield contents
contents = self.read()

@property
def raw_headers(self) -> List[Tuple[bytes, bytes]]:
encoded_headers = [
(
str(header).encode(encoding="utf-8"),
str(value).encode(encoding="utf-8"),
)
for header, value in self.headers.items()
]
return encoded_headers


class BotocoreStubber:
def __init__(self) -> None:
Expand Down Expand Up @@ -66,7 +78,8 @@ def __call__(self, event_name: str, request: Any, **kwargs: Any) -> AWSResponse:
status = e.code # type: ignore[assignment]
headers = e.get_headers() # type: ignore[assignment]
body = e.get_body()
raw_response = MockRawResponse(body)

raw_response = MockRawResponse(response_input=body, headers=dict(headers))
response = AWSResponse(request.url, status, headers, raw_response)

return response