diff --git a/axum/src/response/redirect.rs b/axum/src/response/redirect.rs index b408e8cd..27e183e6 100644 --- a/axum/src/response/redirect.rs +++ b/axum/src/response/redirect.rs @@ -86,10 +86,7 @@ impl Redirect { impl IntoResponse for Redirect { fn into_response(self) -> Response { - match HeaderValue::try_from(self.location) { - Ok(location) => (self.status_code, [(LOCATION, location)]).into_response(), - Err(error) => (StatusCode::INTERNAL_SERVER_ERROR, error.to_string()).into_response(), - } + (self, ()).into_response() } } @@ -133,17 +130,17 @@ impl IntoResponseParts for Redirect { /// ); /// ``` fn into_response_parts(self, mut res: ResponseParts) -> Result { - let location = HeaderValue::try_from(self.location).map_err(|err| { - ( + match HeaderValue::try_from(self.location) { + Ok(location) => { + *res.status_mut() = self.status_code; + res.headers_mut().insert(LOCATION, location); + Ok(res) + } + Err(err) => Err(( StatusCode::INTERNAL_SERVER_ERROR, format!("invalid redirect location: {err}"), - ) - })?; - - *res.status_mut() = self.status_code; - res.headers_mut().insert(LOCATION, location); - - Ok(res) + )), + } } }