FollowRedirects middleware: copy opts from response env #414
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.
Middlewares that come after FollowRedirects might use
opts
for statethey need to keep if they are called multiple times.
The specific use case we have that requires this: Our pool for
gun requires explicit checkout/checkin of the connection. We have a
middleware after FollowRedirects that checks out a connection, passes
it to adapter opts, requests and then checks the connection back in.
However, if
body_as: :chunks
options is used, we, obviously,can't checkin the connection in the middleware as it needs to be passed
to the client after leaving the middleware. But if there was a redirect
to a different host we want to checkin the old connection and checkout
a new one ourselves. So we want to check if adapter options already
have a connection in them and checkin it if present.