Support streaming requests, which return an IO object rather than par… #725
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…sing JSON.
Notify
r? @richardm-stripe
Summary
Adds a new
request_stream
method toStripeObject
,ApiRequestor
andHTTPClient
. When this is used instead ofrequest
, an object which extendsIOBase
will be returned with the response body (implementation differs per HTTP client). Clients will then be able to use this stream to pipe content elsewhere. For errors, we still parse the JSON and raise as appropriate. As part of this, we also had to update custom method decorators to support usingrequest_stream
.Client library methods which return a binary format will use the
request_stream
method to get aStripeStreamResponse
.While this change is not breaking by itself, as soon as we add a method that uses this we will need to release a new major version as custom HTTPClient implementations will need to implement
request_stream
.Motivation
The motivation for this is an upcoming
/pdf
method that will return a pdf instead of JSON.Test plan
Added unit tests to ensure that we wire the IO objects appropriately for each HTTP client.
We'll want to add a more concrete test which uses a stripe-mock endpoint that returns an actual PDF to make sure this works as expected across all supported Python versions.
In the interim, I manually tested this by changing an API call to return a stream and making sure that it works as expected for each HTTP client.