-
Notifications
You must be signed in to change notification settings - Fork 119
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
Rework Request
(and related)
#192
Comments
great post, i think i agree with this direction. thanks for writing this up! should we still have
strongly agree with this in particular—it makes the API a bit less "nice" (for some values of nice) but it's better both for the implementation and for actually modeling how requests are sent (client sends requests, requests don't send themselves). |
A practical implementation of http-rs#192
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 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 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
Done in #194. |
This is essentially a summary of the major improvements to Surf I've been trying to make. there is a lot of overlap with disparate existing issues, which I've linked where appropriate.
In order to improve middleware for Surf (#131), and bring it more in-line with Tide, the following changes should be made:
surf::Request
,surf::Response
rather thanhttp_types::Request
, etc.surf::Request
should be changed to be a more minimalized wrapper aroundhttp_types::Request
(similar toResponse
and Tide.)And also for code hygiene,
Request
should probably not be all of these at once (#152):Future
Additionally related,
Client
should not be generic (#69), (comment on 105), and Middleware may want to be accessible from the present Middleware stack for complete retry/redirect purposes (#169), (#18).Note: Making
Client
1:1 with an actualizedRequest
helps this but doesn't work forkeep-alive
or http2/3+.There is a clean but slightly less ergonomic way to solve most of the API issues here:
surf::Request
be liketide::Request
, only holdhttp_types::Request
.surf::Request
Client::send(req: impl Into<surf::Request>) -> BoxedFuture
rather than making anything be directly await-able.Client
. (Allow applying middleware before know about request uri and methods #126)RequestBuilder
similar totide::ResponseBuilder
.RequestBuilder::send()
be a short-cut for "build and make a newClient
and call.send(self)
on it".surf::method()
return aRequestBuilder
.With middleware:
Regarding
Client
being generic,I see two paths. Either #69,or just making the structure's properties be directly determined by compile-time configuration.dyn
is probably better if we want people to be able to pass external clients that implement some kind of trait. In that case,surf::client_from(trait)
or similar could exist, or possibly even.send::<ClientType>()
.Update: see #193 "
dyn HttpClient
". (Merged)Ideally I think that
Client
would be the thing that actualizes/sendsRequest
s and holds the middleware stack, similar to what #109 asks for.This was an older WIP, see #194 for a full compiling patch of the above proposal!
I have a WIP patch of some of this stuff, but in the form of a
SurfBuilder
, which has a structure like so and is not much cleaner than today, although it does allow middleware to operate onsurf::Request
andsurf::Response
. I prefer the approach I described above.tl;dr things become much cleaner and simpler if:
surf::method()
returns does not have.middleware()
(@yoshuawuyts?) (Allow applying middleware before know about request uri and methods #126)Client
is made. See RequestBuilder: add.middleware()
Fishrock123/surf#1Whateversurf::method()
returns does notimpl Future
. (@yoshuawuyts)IntoFuture
comes would be better...)RequestBuilder
. See src: overhaul Client, rework Request and Middleware, add builder #194Client
is no longer generic. (@goto-bus-stop?, @yoshuawuyts?) (Making theClient
to use dynamic dispatch #69) (Impossible to Create a Static Client? #150)The text was updated successfully, but these errors were encountered: