Skip to content

Commit

Permalink
Merge pull request #85 from chris-morgan/master
Browse files Browse the repository at this point in the history
Handle HEAD requests properly.
  • Loading branch information
reem committed Jul 3, 2015
2 parents 72c40de + 94ea860 commit a518e09
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ impl Router {
}
});
}
// If GET is there, HEAD is also there.
if options.contains(&method::Get) && !options.contains(&method::Head) {
options.push(method::Head);
}

let mut res = Response::with(status::Ok);
res.headers.set(headers::Allow(options));
Expand All @@ -141,7 +145,12 @@ impl Router {
}

fn handle_method(&self, req: &mut Request, path: &str) -> IronResult<Response> {
let matched = match self.recognize(&req.method, path) {
let mut matched = self.recognize(&req.method, path);
if matched.is_none() && req.method == method::Head {
// For HEAD, fall back to GET. Hyper ensures no response body is written.
matched = self.recognize(&method::Get, path);
}
let matched = match matched {
Some(matched) => matched,
// No match.
None => return Err(IronError::new(NoRoute, status::NotFound))
Expand Down

0 comments on commit a518e09

Please sign in to comment.