Repository: seanmonstar/reqwest (language: rust)

Issue:
Wrapping the default redirect policy
It should be possible to specify a custom redirect policy that extends the default behavior without having to reimplement it.


Discussion / hints:
What exactly do you mean? You can create a `RedirectPolicy::limited(10)`, and use that inside your custom policy, right?
That would be possible if `RedirectPolicy::redirect()` was public. Maybe I'm missing something? Otherwise I'd be happy to make a PR.
Oh, I see... Hm, I tried erring on the side of caution as much as possible in reqwest, such that if it didn't seem like something needed to be public, it isn't. That way, internals could change.

Looking at this method, it *looks* probably safe to just make it public... 😟 😆 

Fix patch:
diff --git a/src/redirect.rs b/src/redirect.rs
index 273ff04e4..4c8f290c5 100644
--- a/src/redirect.rs
+++ b/src/redirect.rs
@@ -91,7 +91,27 @@ impl RedirectPolicy {
         }
     }
 
-    fn redirect(&self, attempt: RedirectAttempt) -> RedirectAction {
+    /// Apply this policy to a given [`RedirectAttempt`] to produce a [`RedirectAction`].
+    ///
+    /// # Note
+    ///
+    /// This method can be used together with RedirectPolicy::custom()
+    /// to construct one RedirectPolicy that wraps another.
+    ///
+    /// # Example
+    ///
+    /// ```rust
+    /// # use reqwest::{Error, RedirectPolicy};
+    /// #
+    /// # fn run() -> Result<(), Error> {
+    /// let custom = RedirectPolicy::custom(|attempt| {
+    ///     eprintln!("Location: {:?}", attempt.url());
+    ///     RedirectPolicy::default().redirect(attempt)
+    /// });
+    /// # Ok(())
+    /// # }
+    /// ```
+    pub fn redirect(&self, attempt: RedirectAttempt) -> RedirectAction {
         match self.inner {
             Policy::Custom(ref custom) => custom(attempt),
             Policy::Limit(max) => {


Test patch: