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

RequestBuilder: add .middleware() #1

Closed
wants to merge 3 commits into from

Conversation

Fishrock123
Copy link
Owner

@Fishrock123 Fishrock123 commented Jul 10, 2020

Possible additions to http-rs#194, which would be less breaking and possibly more ergonomic, and possibly light enough to warrant doing.

Open questions:

  • What to do if Request is used in an existing Client? The middleware would be lost. Maybe panic. Maybe do nothing."
    • See the second commit. Per-request middleware...

src/client.rs Outdated Show resolved Hide resolved
A practical implementation of http-rs#192

Some form of this is required in order to make middleware use
`surf::Request` and `surf::Response`. Doing so means that those types,
particularly request, must own their related `http_types` data.
Refs:  http-rs#131

This necessitates that `surf::{method}()` return some kind of builder,
as is include here as `RequestBuilder`, which includes methods for
the common request manipulations when creating new requests.
As added convience, the builder can be awaited directly, but does not
allow for middleware without use of `Client` due to confusing
semantics regarding combining per-request and per-client middleware.

PR-URL: http-rs#194
A possible addition to http-rs#194,
which would be less breaking and possibly more ergonomic, and
possibly light enough to warrant doing.
I don't exactly fancy this patch, but here it is anyways.

This adds an optional middleware stack to `Request`, allowing
`RequestBuilder` and one-off requests to have middleware added
onto them, but also allows one-off requests with middleware to
have the middleware stack be appended to client middleware
for just that request.
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.

1 participant