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

Middleware API #1133

Closed
wants to merge 2 commits into from
Closed

Middleware API #1133

wants to merge 2 commits into from

Conversation

florimondmanca
Copy link
Member

And here I am pitching the idea of a middleware API again… :-)

As I mentioned in #984 (comment), and more recently in #1110 (comment), there is a variety of use cases that don't fall in the "make a custom transport" domain, the "subclass the client without using private API" domain. In general this is transport-agnostic feature that intercepts the request/response cycle, for example...

  • Caching: look up the request key in a cache, and optionally return early with a response w/o hitting the transport.
  • Throttling: defer the sending of the request until a throttle policy would be satisfied.
  • HSTS (?): modify the request to use HTTPS if the requested website is on the HSTS Preload List.

After playing with ideas, this PR is all we would need to support a middleware API that would support the above use cases and, I believe, many more.

Core ideas are…

  • Requests are passed through a stack of middleware. The processing stack is:
# Process request...
middleware_1
    ... middleware_n
        send_handling_redirects() 
        # <Ultimately we dispatch to the transport>
        # Process the response...
    ... middleware_n
middleware_1

@florimondmanca
Copy link
Member Author

🤔 -> #1134

@florimondmanca florimondmanca deleted the middleware branch November 20, 2020 20:34
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.

None yet

1 participant