refactor: remove duplication between IntoResponse and IntoResponseParts for Redirect (#3743)

This commit is contained in:
David Pedersen
2026-05-05 14:19:09 +02:00
parent 4eed2f6c13
commit 2b38288f61
+10 -13
View File
@@ -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<ResponseParts, Self::Error> {
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)
)),
}
}
}