{"id":"31054cf682b5045e","repo":"seanmonstar/reqwest","slug":"error-following-redirect","errorCode":null,"errorMessage":"error following redirect","messagePattern":"error following redirect","errorType":"exception","errorClass":"reqwest::Error","httpStatus":null,"severity":"error","filePath":"src/error.rs","lineNumber":365,"sourceCode":"\npub(crate) fn body<E: Into<BoxError>>(e: E) -> Error {\n    Error::new(Kind::Body, Some(e))\n}\n\npub(crate) fn decode<E: Into<BoxError>>(e: E) -> Error {\n    Error::new(Kind::Decode, Some(e))\n}\n\npub(crate) fn request<E: Into<BoxError>>(e: E) -> Error {\n    Error::new(Kind::Request, Some(e))\n}\n\npub(crate) fn dns<E: Into<BoxError>>(e: E) -> BoxError {\n    Box::new(DnsError { inner: e.into() })\n}\n\npub(crate) fn redirect<E: Into<BoxError>>(e: E, url: Url) -> Error {\n    Error::new(Kind::Redirect, Some(e)).with_url(url)\n}\n\npub(crate) fn status_code(\n    url: Url,\n    status: StatusCode,\n    #[cfg(not(all(target_arch = \"wasm32\", any(target_os = \"unknown\", target_os = \"none\"))))] reason: Option<hyper::ext::ReasonPhrase>,\n) -> Error {\n    Error::new(\n        Kind::Status(\n            status,\n            #[cfg(not(all(\n                target_arch = \"wasm32\",\n                any(target_os = \"unknown\", target_os = \"none\")\n            )))]\n            reason,\n        ),\n        None::<Error>,\n    )","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/seanmonstar/reqwest/blob/17e9bcb51c46edebfb6f5f2f5184b51dac4b3a7d/src/error.rs#L347-L383","documentation":"The `Kind::Redirect` error from `error::redirect(...)` (error.rs:364-366). It fires when the redirect policy itself errors — most often because the redirect `Location` has a disallowed scheme, the redirect chain exceeds the limit (default 10), or a redirect loop is detected.","triggerScenarios":"A `Location` response header pointing to a non-http(s) scheme on an https-only client (redirect.rs:325-328 wraps `url_bad_scheme`); more than `redirect(Policy::limit(n))` hops; a self-referential redirect loop; a custom `RedirectPolicy` returning `Policy::error(...)`.","commonSituations":"Site redirects from https to http while the client is https-only; infinitely redirecting auth flow; CDN redirect chain deeper than the default 10; custom policy enforcing allow-lists that rejects a target.","solutions":["Inspect `e.url()` to see where the redirect chain stopped.","Raise the limit via `Client::builder().redirect(Policy::limited(20))` if the chain is legitimately long.","If the issue is an https→http downgrade, decide explicitly: allow it with `Policy::default()` or keep https-only and fail.","For custom policies, return `Policy::stop()` instead of `Policy::error(...)` to keep the last response rather than erroring."],"exampleFix":"// before\nlet client = Client::builder().build()?; // default limit 10\nlet r = client.get(url).send().await?; // 'error following redirect' on long chain\n\n// after\nlet client = Client::builder()\n    .redirect(reqwest::redirect::Policy::limited(30))\n    .build()?;\nlet r = client.get(url).send().await?;","handlingStrategy":"validation","validationCode":"// Pre-validate redirect tolerance for known chains.\nlet client = Client::builder()\n    .redirect(reqwest::redirect::Policy::limited(max_hops_for(url)))\n    .build()?;\n","typeGuard":"fn is_redirect_error(e: &reqwest::Error) -> bool { e.is_redirect() }\n","tryCatchPattern":"let resp = match client.get(&url).send().await {\n    Ok(r) => r,\n    Err(e) if e.is_redirect() => {\n        log::warn!(\"redirect stopped at {:?}\", e.url());\n        return Err(e.into());\n    }\n    Err(e) => return Err(e.into()),\n};","preventionTips":["Tune redirect::Policy::limit to the longest legitimate chain.","For https-only clients, expect https→http downgrades to error; decide intentionally.","Return Policy::stop() from custom policies when you want to keep the last response."],"tags":["redirect","policy","url","network"],"analyzedSha":"17e9bcb51c46edebfb6f5f2f5184b51dac4b3a7d","analyzedAt":"2026-08-06T01:23:05.134Z","schemaVersion":2}