Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

axum-extra: log rejections of TypedHeader #2738

Merged
merged 5 commits into from
May 27, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion axum-extra/src/typed_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use axum::{
response::{IntoResponse, IntoResponseParts, Response, ResponseParts},
};
use headers::{Header, HeaderMapExt};
use http::request::Parts;
use http::{request::Parts, StatusCode};
use std::convert::Infallible;

/// Extractor and response that works with typed header values from [`headers`].
Expand Down Expand Up @@ -156,6 +156,13 @@ impl TypedHeaderRejectionReason {

impl IntoResponse for TypedHeaderRejection {
fn into_response(self) -> Response {
let status = StatusCode::BAD_REQUEST;
let body = self.to_string();
axum_core::__log_rejection!(
rejection_type = Self,
body_text = body,
status = status,
);
jplatte marked this conversation as resolved.
Show resolved Hide resolved
(http::StatusCode::BAD_REQUEST, self.to_string()).into_response()
jplatte marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down
Loading