reqwest-tracing: add method for handling cancelled requests #253
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.
Motivation
When a request is created and possibly partially sent, but the future is dropped before being polled to completion, then
on_request_endis not called.Solution
This adds another method for this scenario so that either
on_request_endoron_request_cancelledis always called if the middleware finishes.The method has a provided implementation so that it is not a breaking change.
This new method is different from the other two in that it does not take
&mut Extensions. This is due to technical difficulities as I would need to keep the mutable reference in the drop guard, but at the same time the future that has access to the same mutable reference would be run. I don't think there is a way to solve this without unsafe and raw pointers (or maybe self-referential structs). So I've decided not to provide the extensions instead.Alternatives
Errorenum for this and reuseon_request_end. This would also force us to solve the issue around the&mut Extensionsso I think this would also require unsafe code.