diff --git a/src/header.rs b/src/header.rs index 0d6b3cc..a990359 100644 --- a/src/header.rs +++ b/src/header.rs @@ -2,13 +2,19 @@ use ascii::AsciiString; use error::Error; use std::str::FromStr; -#[derive(Debug, Clone)] +#[derive(Clone)] /// Wrapper type for a header line. pub struct Header { line: AsciiString, index: usize, } +impl ::std::fmt::Debug for Header { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::result::Result<(), ::std::fmt::Error> { + write!(f, "{}", self.line) + } +} + impl Header { /// The header name. /// diff --git a/src/request.rs b/src/request.rs index a32817f..e099fdd 100644 --- a/src/request.rs +++ b/src/request.rs @@ -40,10 +40,13 @@ pub struct Request { impl ::std::fmt::Debug for Request { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::result::Result<(), ::std::fmt::Error> { + let url = self.to_url().unwrap(); + let query = combine_query(&url, &self.query); write!( f, - "Request[{} {}, {}, {:?}]", - self.method, self.path, self.query, self.headers + "Request({} {}{}, {:?})", + self.method, url.path(), query, + self.headers ) } } diff --git a/src/test/simple.rs b/src/test/simple.rs index e55de81..f689bc3 100644 --- a/src/test/simple.rs +++ b/src/test/simple.rs @@ -96,3 +96,32 @@ fn escape_path() { let s = String::from_utf8_lossy(&vec); assert!(s.contains("GET /escape_path%20here HTTP/1.1")) } + +#[test] +fn request_debug() { + let req = get("/my/page") + .set("Authorization", "abcdef") + .set("Content-Length", "1234") + .set("Content-Type", "application/json") + .build(); + + let s = format!("{:?}", req); + + assert_eq!( + s, + "Request(GET /my/page, [Authorization: abcdef, \ + Content-Length: 1234, Content-Type: application/json])" + ); + + let req = get("/my/page?q=z") + .query("foo", "bar baz") + .set("Authorization", "abcdef") + .build(); + + let s = format!("{:?}", req); + + assert_eq!( + s, + "Request(GET /my/page?q=z&foo=bar%20baz, [Authorization: abcdef])" + ); +}