From 44863ed53ab8912409ace2a92aa73cae6e33a471 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 8 Nov 2016 15:43:53 -0500 Subject: [PATCH 1/2] Avoid random vector construction --- src/dist.rs | 7 +++---- src/util/mod.rs | 5 +++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/dist.rs b/src/dist.rs index ad53fa7a7f1..6678fed4d5a 100644 --- a/src/dist.rs +++ b/src/dist.rs @@ -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(false); if wants_html { self.dist.call(&mut RequestProxy { other: req, diff --git a/src/util/mod.rs b/src/util/mod.rs index e48256e771a..663f0905339 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -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)> { From c9e1c375841ddc4a21d7792ecabbe4b7c7cc0a46 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 8 Nov 2016 15:48:45 -0500 Subject: [PATCH 2/2] Assume html if no Accept header is presented Fixes #163. --- src/dist.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dist.rs b/src/dist.rs index 6678fed4d5a..6ed999a770f 100644 --- a/src/dist.rs +++ b/src/dist.rs @@ -39,7 +39,7 @@ impl Handler for Middleware { // serve up that page. Otherwise proxy on to the rest of the app. let wants_html = req.headers().find("Accept").map(|accept| { accept.iter().any(|s| s.contains("html")) - }).unwrap_or(false); + }).unwrap_or(true); // If no Accept header is specified, serve up html. if wants_html { self.dist.call(&mut RequestProxy { other: req,