feat(client): add SendRequest::try_send_request()
method
#3691
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.
This change adds a
try_send_request()
method toSendRequest
. This method returns aTrySendError
type, which allows for returning the request back to the caller if an error occured between queuing and trying to write the request.This method is added for both
http1
andhttp2
.Closes #3673
Closes seanmonstar/reqwest#2325
(Well, after hyper-util makes use of it.)
Problem
If you try to
send_request(req)
at the same time the server is closing the connection, it's possible hyper will notice the HUP before the request gets serialized. If so, theoretically the request is safe to try on another connection.But there isn't a mechanism for hyper to give the request back. And since the pool was moved out of hyper, it doesn't know how to just grab another connection.
Need: a mechanism to return the request on specific kinds of errors.
Options
try_send_request(req)
, which returns aTrySendError
.hyper::Error
.req.extensions()
.TrySendError
Pros:
std::sync::mpsc::TrySendError
as prior art.Cons:
http1::SendRequest
andhttp2::SendRequest
.send_request()
have handled this?fn send()
and hidetry_send_request()
andsend_request()
.Embed in
hyper::Error
After writing all this out, this is probably not possible.
Pros:
Cons:
Error::request()
set of APIs seems to pollute the type.ext
API can access it...Error
around but didn't expect theRequest<B>
to live with it?ext
be set to signal to hyper that it's OK? Then it becomes opt-in.Request<B>
if the body is!Send
ext
passed converts into anAny
...Pass
ext::CaptureTrySend
?Pros:
B
Error
for longer than expectedCons:
req.extensions()
for basically every request...