Skip to main content

redirect_error

Function redirect_error 

Source
pub fn redirect_error(status: u16, headers: &Headers) -> Error
Expand description

The error for a redirect (3xx) response, which the bundled providers never follow: an allama::Error::UnexpectedResponse with the status, the response’s error_context, and an authored message naming the host the Location header points to (never its path or query, which may carry tokens). It is not retryable: the server answers the same way again.

ReqwestTransport::new does not follow redirects, so the bundled providers see the redirect itself and map it here, through HttpResponse::map_error.

use allama::Error;
use allama_http::{Headers, redirect_error};

let headers: Headers = [("location", "http://169.254.169.254/latest?token=x")].into_iter().collect();
let err = redirect_error(307, &headers);
assert!(matches!(err, Error::UnexpectedResponse { .. }));
assert_eq!(err.status(), Some(307));
assert!(!err.is_retryable());
assert_eq!(
    err.to_string(),
    "unexpected response: HTTP 307: the server redirected the request to `169.254.169.254`; \
     redirects are not followed",
);