Skip to content

Commit

Permalink
Make it set content type only if not set by the user
Browse files Browse the repository at this point in the history
  • Loading branch information
benwis committed Sep 29, 2023
1 parent c923667 commit c688e2f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions integrations/axum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,16 +773,20 @@ async fn generate_response(
if let Some(status) = res_options.status {
*res.status_mut() = status
}
// Set the Content Type headers on all responses. This makes Firefox show the page source
// without complaining

let headers = res.headers_mut();
headers.insert(
http::header::CONTENT_TYPE,
HeaderValue::from_str("text/html; charset=utf-8").unwrap(),
);

let mut res_headers = res_options.headers.clone();
headers.extend(res_headers.drain());

if !headers.contains_key(http::header::CONTENT_TYPE){
// Set the Content Type headers on all responses. This makes Firefox show the page source
// without complaining
headers.insert(
http::header::CONTENT_TYPE,
HeaderValue::from_str("text/html; charset=utf-8").unwrap(),
);
}
res
}
#[tracing::instrument(level = "info", fields(error), skip_all)]
Expand Down

0 comments on commit c688e2f

Please sign in to comment.