-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
fix parse_response to handle streaming responses #6415
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great change! I think we can assume that the event streaming response needs to be a stream as well, but we can address this in the next iteration as well.
if response_dict["status_code"] >= 300: | ||
response_dict["body"] = response.data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an FYI: This explicitly contains any redirections (3xx). There are no 3xx http response status codes in the specifications, but these responses might have a response body. But imho it's safe to assume that there are not streaming responses in 300+ status codes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, just doing what the client does 🤷
localstack/aws/client.py
Outdated
# TODO | ||
LOG.warning( | ||
"don't know how to parse an event stream output for %s.%s", | ||
operation.service_model.service_name, | ||
operation.name, | ||
) | ||
response_dict["body"] = response.data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just dig a bit into this:
- The parsers create an instance of the
EventStream
withresponse['body']
in this case: parsers.py#L348 - The
EventStream
class in botocore expects this param to be a raw bytes stream:
eventstream.py#L595
So I think we should just use the _ResponseStream
here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, yea i added an additional _RawStream
wrapper that exposes the interface botocore's EventStream
object seems to expect. i'm too lazy to test this right now, so leaving a TODO for the next person :P
8fb5eed
to
e4bd11d
Compare
e4bd11d
to
26eb419
Compare
26eb419
to
cdd7552
Compare
cdd7552
to
81dada4
Compare
This PR fixes an issue/limitation of the
parse_response
operation in our aws client module.The problem was that we were not really implementing the parsing logic of botocore correctly, in particular when streaming binary responses are expected, like in
s3.GetObject
, which caused a problem here: https://github.com/boto/botocore/blob/ae44d1de241c13626d05a9301cf62e460833c950/botocore/parsers.py#L910-L914In boto, when you call
s3_client.get_object(...)
, theBody
attribute of the response (i.e., the payload), will not actually be bytes, but a readableio
object. This PR introduces the same behavior for theparse_response
method.I modeled the implementation after the version in boto core https://github.com/boto/botocore/blob/ae44d1de241c13626d05a9301cf62e460833c950/botocore/endpoint.py#L65-L74
Future work is
has_event_stream_output
, which I think covers things like the kinesis shard iterator.