Skip to content

Commit c2184cf

Browse files
authored
Merge pull request #464 from tamird/fix-no-accept
Assume html if no Accept header is presented
2 parents 7b6752d + c9e1c37 commit c2184cf

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Diff for: src/dist.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ impl Handler for Middleware {
3737

3838
// Second, if we're requesting html, then we've only got one page so
3939
// serve up that page. Otherwise proxy on to the rest of the app.
40-
let wants_html = {
41-
let content = req.headers().find("Accept").unwrap_or(Vec::new());
42-
content.iter().any(|s| s.contains("html"))
43-
};
40+
let wants_html = req.headers().find("Accept").map(|accept| {
41+
accept.iter().any(|s| s.contains("html"))
42+
}).unwrap_or(true); // If no Accept header is specified, serve up html.
4443
if wants_html {
4544
self.dist.call(&mut RequestProxy {
4645
other: req,

Diff for: src/util/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ impl<'a> RequestUtils for Request + 'a {
9393
}
9494

9595
fn wants_json(&self) -> bool {
96-
let content = self.headers().find("Accept").unwrap_or(Vec::new());
97-
content.iter().any(|s| s.contains("json"))
96+
self.headers().find("Accept").map(|accept| {
97+
accept.iter().any(|s| s.contains("json"))
98+
}).unwrap_or(false)
9899
}
99100

100101
fn pagination(&self, default: usize, max: usize) -> CargoResult<(i64, i64)> {

0 commit comments

Comments
 (0)