Skip to content

Commit e3ebbc5

Browse files
Fix mime type for js files
1 parent cb6d6e4 commit e3ebbc5

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/web/releases.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,12 +1657,13 @@ mod tests {
16571657
wrapper(|env| {
16581658
let web = env.frontend();
16591659

1660-
let empty_data = format!("data: [{}]", vec!["0"; 30].join(","));
1660+
let empty_data = format!("data: [{}]", vec!["0"; 30].join(", "));
16611661

16621662
// no data / only zeros without releases
16631663
let response = web.get("/releases/activity/").send()?;
16641664
assert!(response.status().is_success());
1665-
assert_eq!(response.text().unwrap().matches(&empty_data).count(), 2);
1665+
let text = response.text();
1666+
assert_eq!(text.unwrap().matches(&empty_data).count(), 2);
16661667

16671668
env.fake_release().name("some_random_crate").create()?;
16681669
env.fake_release()
@@ -1690,9 +1691,9 @@ mod tests {
16901691
assert!(response.status().is_success());
16911692
let text = response.text().unwrap();
16921693
// counts contain both releases
1693-
assert!(text.contains(&format!("data: [{},2]", vec!["0"; 29].join(","))));
1694+
assert!(text.contains(&format!("data: [{}, 2]", vec!["0"; 29].join(", "))));
16941695
// failures only one
1695-
assert!(text.contains(&format!("data: [{},1]", vec!["0"; 29].join(","))));
1696+
assert!(text.contains(&format!("data: [{}, 1]", vec!["0"; 29].join(", "))));
16961697

16971698
Ok(())
16981699
})

src/web/statics.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ fn build_static_css_response(content: &'static str) -> impl IntoResponse {
2626
}
2727

2828
async fn set_needed_static_headers(req: Request, next: Next) -> Response {
29-
let is_opensearch_xml = req.uri().path().ends_with("/opensearch.xml");
29+
let req_path = req.uri().path();
30+
let is_opensearch_xml = req_path.ends_with("/opensearch.xml");
31+
let is_js = req_path.ends_with(".js");
3032

3133
let mut response = next.run(req).await;
3234

@@ -43,6 +45,13 @@ async fn set_needed_static_headers(req: Request, next: Next) -> Response {
4345
CONTENT_TYPE,
4446
HeaderValue::from_static("application/opensearchdescription+xml"),
4547
);
48+
} else if is_js {
49+
// overwrite the content type for javascript files,
50+
// otherwise mime-guess would return `text/javascript`.
51+
response.headers_mut().insert(
52+
CONTENT_TYPE,
53+
HeaderValue::from_static("application/javascript"),
54+
);
4655
}
4756

4857
response

0 commit comments

Comments
 (0)