Skip to content

Assume html if no Accept header is presented #464

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

Merged
merged 2 commits into from
Nov 8, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 3 additions & 4 deletions src/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ impl Handler for Middleware {

// Second, if we're requesting html, then we've only got one page so
// serve up that page. Otherwise proxy on to the rest of the app.
let wants_html = {
let content = req.headers().find("Accept").unwrap_or(Vec::new());
content.iter().any(|s| s.contains("html"))
};
let wants_html = req.headers().find("Accept").map(|accept| {
accept.iter().any(|s| s.contains("html"))
}).unwrap_or(true); // If no Accept header is specified, serve up html.
if wants_html {
self.dist.call(&mut RequestProxy {
other: req,
Expand Down
5 changes: 3 additions & 2 deletions src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ impl<'a> RequestUtils for Request + 'a {
}

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

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