better debug formatting of requests
This commit is contained in:
@@ -2,13 +2,19 @@ use ascii::AsciiString;
|
|||||||
use error::Error;
|
use error::Error;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Clone)]
|
||||||
/// Wrapper type for a header line.
|
/// Wrapper type for a header line.
|
||||||
pub struct Header {
|
pub struct Header {
|
||||||
line: AsciiString,
|
line: AsciiString,
|
||||||
index: usize,
|
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 {
|
impl Header {
|
||||||
/// The header name.
|
/// The header name.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -40,10 +40,13 @@ pub struct Request {
|
|||||||
|
|
||||||
impl ::std::fmt::Debug for Request {
|
impl ::std::fmt::Debug for Request {
|
||||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::result::Result<(), ::std::fmt::Error> {
|
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!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"Request[{} {}, {}, {:?}]",
|
"Request({} {}{}, {:?})",
|
||||||
self.method, self.path, self.query, self.headers
|
self.method, url.path(), query,
|
||||||
|
self.headers
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,3 +96,32 @@ fn escape_path() {
|
|||||||
let s = String::from_utf8_lossy(&vec);
|
let s = String::from_utf8_lossy(&vec);
|
||||||
assert!(s.contains("GET /escape_path%20here HTTP/1.1"))
|
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])"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user