mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-19 00:00:14 +02:00
refactor: remove duplication between IntoResponse and IntoResponseParts for Redirect (#3743)
This commit is contained in:
@@ -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)
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user