webdriver: server: improve logging of http requests and responses
authorAndreas Tolfsen <ato@mozilla.com>
Thu, 20 Apr 2017 13:55:59 +0100
changeset 428143 e1a198ffa22926895f81c40504707e70b0a14c4f
parent 428142 283f77eb68b1a48ee786be59edb556364b7499c6
child 428144 d313a2a5bc7e20173965cfb20113068b97502419
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
webdriver: server: improve logging of http requests and responses HTTP requests and responses will now be logged in a similar style as Marionette chatter in geckodriver (following https://github.com/mozilla/geckodriver/pull/636) and in the Marionette server in Gecko, by employing arrows. The logging of responses is reduced from two log entries, to one. It also makes use of the fmt::Display trait of the status. For requests, the HTTP method, URI, and full body is included. Source-Repo: https://github.com/mozilla/webdriver-rust Source-Revision: 7e2a2042fa80018c8bce8bddee81ab6985db65f8 committer: jgraham <james@hoppipolla.co.uk>
testing/webdriver/src/server.rs
--- a/testing/webdriver/src/server.rs
+++ b/testing/webdriver/src/server.rs
@@ -158,82 +158,86 @@ impl <U: WebDriverExtensionRoute> HttpHa
     fn new(api: WebDriverHttpApi<U>, chan: Sender<DispatchMessage<U>>) -> HttpHandler<U> {
         HttpHandler {
             chan: Mutex::new(chan),
             api: Mutex::new(api)
         }
     }
 }
 
-impl <U: WebDriverExtensionRoute> Handler for HttpHandler<U> {
+impl<U: WebDriverExtensionRoute> Handler for HttpHandler<U> {
     fn handle(&self, req: Request, res: Response) {
         let mut req = req;
         let mut res = res;
 
         let mut body = String::new();
         if let Method::Post = req.method {
             req.read_to_string(&mut body).unwrap();
         }
-        debug!("Got request {} {:?}", req.method, req.uri);
+
+        debug!("→ {} {} {}", req.method, req.uri, body);
+
         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[..])
-                        },
-                        Err(_) => return
+                        Ok(ref api) => api.decode_request(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));
+                                let res =
+                                    c.send(DispatchMessage::HandleWebDriver(message, send_res));
                                 match res {
                                     Ok(x) => x,
                                     Err(_) => {
                                         error!("Something terrible happened");
-                                        return
+                                        return;
                                     }
                                 }
-                            },
+                            }
                             Err(_) => {
                                 error!("Something terrible happened");
-                                return
+                                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)
+                            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())
                     }
+                    Err(err) => (err.http_status(), err.to_json_string()),
                 };
-                debug!("Returning status {:?}", status);
-                debug!("Returning body {}", resp_body);
+
+                debug!("← {} {}", status, resp_body);
+
                 {
                     let resp_status = res.status_mut();
                     *resp_status = status;
                 }
-                res.headers_mut().set(
-                    ContentType(Mime(TopLevel::Application, SubLevel::Json,
-                                     vec![(Attr::Charset, Value::Utf8)])));
-                res.headers_mut().set(CacheControl(vec![CacheDirective::NoCache]));
+                res.headers_mut()
+                    .set(ContentType(Mime(TopLevel::Application,
+                                          SubLevel::Json,
+                                          vec![(Attr::Charset, Value::Utf8)])));
+                res.headers_mut()
+                    .set(CacheControl(vec![CacheDirective::NoCache]));
+
                 res.send(&resp_body.as_bytes()).unwrap();
-            },
+            }
             _ => {}
         }
     }
 }
 
 pub fn start<T, U>(address: SocketAddr,
                    handler: T,
                    extension_routes: &[(Method, &str, U)])