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

FollowRedirects middleware: copy opts from response env #414

Merged

Conversation

rinpatch
Copy link
Contributor

@rinpatch rinpatch commented Sep 4, 2020

Middlewares that come after FollowRedirects might use opts for state
they 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.

Middlewares that come after FollowRedirects might use `opts` for state
they 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.
@rinpatch rinpatch force-pushed the fix/redirect-middleware-ignores-env branch from 3484e0f to 3a2789d Compare September 4, 2020 18:44
github-actions bot pushed a commit to kphrx/pleroma that referenced this pull request Sep 5, 2020
Requires a patched Tesla due to upstream not saving opts between
redirects, patch submitted at elixir-tesla/tesla#414
@teamon teamon merged commit 9f7261c into elixir-tesla:master Sep 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants