Bug 1396824 - Treat HEAD requests as GET requests when decoding and return 200 before executing
MozReview-Commit-ID: 6cs8YAkEDkM
--- a/testing/webdriver/src/server.rs
+++ b/testing/webdriver/src/server.rs
@@ -171,55 +171,64 @@ impl<U: WebDriverExtensionRoute> Handler
let mut body = String::new();
if let Method::Post = req.method {
req.read_to_string(&mut body).unwrap();
}
debug!("-> {} {} {}", req.method, req.uri, body);
+ let (head_req, equivalent_req_method) = match req.method {
+ Method::Head => (true, Method::Get),
+ method => (false, method)
+ };
+
match req.uri {
AbsolutePath(path) => {
let msg_result = {
// The fact that this locks for basically the whole request doesn't
// matter as long as we are only handling one request at a time.
match self.api.lock() {
- Ok(ref api) => api.decode_request(req.method, &path[..], &body[..]),
+ Ok(ref api) => api.decode_request(equivalent_req_method, &path[..], &body[..]),
Err(_) => return,
}
};
let (status, resp_body) = match msg_result {
Ok(message) => {
- let (send_res, recv_res) = channel();
- match self.chan.lock() {
- Ok(ref c) => {
- let res =
- c.send(DispatchMessage::HandleWebDriver(message, send_res));
- match res {
- Ok(x) => x,
- Err(_) => {
- error!("Something terrible happened");
- return;
+ if head_req {
+ (StatusCode::Ok, String::new())
+ } else {
+ let (send_res, recv_res) = channel();
+ match self.chan.lock() {
+ Ok(ref c) => {
+ let res =
+ c.send(DispatchMessage::HandleWebDriver(message, send_res));
+ match res {
+ Ok(x) => x,
+ Err(_) => {
+ error!("Something terrible happened");
+ return;
+ }
}
}
+ Err(_) => {
+ error!("Something terrible happened");
+ return;
+ }
}
- Err(_) => {
- error!("Something terrible happened");
- return;
+ match recv_res.recv() {
+ Ok(data) => {
+ match data {
+ Ok(response) => (StatusCode::Ok, response.to_json_string()),
+ Err(err) => (err.http_status(), err.to_json_string()),
+ }
+ }
+ Err(e) => panic!("Error reading response: {:?}", e),
}
}
- match recv_res.recv() {
- Ok(data) => {
- match data {
- Ok(response) => (StatusCode::Ok, response.to_json_string()),
- Err(err) => (err.http_status(), err.to_json_string()),
- }
- }
- Err(e) => panic!("Error reading response: {:?}", e),
- }
}
Err(err) => (err.http_status(), err.to_json_string()),
};
debug!("<- {} {}", status, resp_body);
{
let resp_status = res.status_mut();