resp.status() return u16

This commit is contained in:
Martin Algesten
2018-07-01 09:04:50 +02:00
parent 4dc47958c6
commit 567a19a656
4 changed files with 14 additions and 14 deletions

View File

@@ -67,7 +67,7 @@ impl Response {
/// ``` /// ```
/// let resp = ureq::Response::new(401, "Authorization Required", "Please log in"); /// let resp = ureq::Response::new(401, "Authorization Required", "Please log in");
/// ///
/// assert_eq!(*resp.status(), 401); /// assert_eq!(resp.status(), 401);
/// ``` /// ```
pub fn new(status: u16, status_text: &str, body: &str) -> Self { pub fn new(status: u16, status_text: &str, body: &str) -> Self {
let r = format!("HTTP/1.1 {} {}\r\n\r\n{}\n", status, status_text, body); let r = format!("HTTP/1.1 {} {}\r\n\r\n{}\n", status, status_text, body);
@@ -87,8 +87,8 @@ impl Response {
} }
/// The status as a u16: `200` /// The status as a u16: `200`
pub fn status(&self) -> &u16 { pub fn status(&self) -> u16 {
&self.status self.status
} }
/// The status text: `OK` /// The status text: `OK`
@@ -171,7 +171,7 @@ impl Response {
/// assert!(resp.error()); /// assert!(resp.error());
/// ///
/// // synthetic error code 400 /// // synthetic error code 400
/// assert_eq!(*resp.status(), 400); /// assert_eq!(resp.status(), 400);
/// ///
/// // tell that it's synthetic. /// // tell that it's synthetic.
/// assert!(resp.synthetic()); /// assert!(resp.synthetic());
@@ -379,7 +379,7 @@ impl Response {
/// let read = Cursor::new(text.to_string().into_bytes()); /// let read = Cursor::new(text.to_string().into_bytes());
/// let resp = ureq::Response::from_read(read); /// let resp = ureq::Response::from_read(read);
/// ///
/// assert_eq!(*resp.status(), 401); /// assert_eq!(resp.status(), 401);
/// ``` /// ```
pub fn from_read(reader: impl Read) -> Self { pub fn from_read(reader: impl Read) -> Self {
Self::do_from_read(reader).unwrap_or_else(|e| e.into()) Self::do_from_read(reader).unwrap_or_else(|e| e.into())
@@ -632,7 +632,7 @@ mod tests {
let s = format!("HTTP/1.1 BORKED\r\n"); let s = format!("HTTP/1.1 BORKED\r\n");
let resp: Response = s.parse::<Response>().unwrap_err().into(); let resp: Response = s.parse::<Response>().unwrap_err().into();
assert_eq!(resp.http_version(), "HTTP/1.1"); assert_eq!(resp.http_version(), "HTTP/1.1");
assert_eq!(*resp.status(), 500); assert_eq!(resp.status(), 500);
assert_eq!(resp.status_text(), "Bad Status"); assert_eq!(resp.status_text(), "Bad Status");
assert_eq!(resp.content_type(), "text/plain"); assert_eq!(resp.content_type(), "text/plain");
let v = resp.into_string().unwrap(); let v = resp.into_string().unwrap();

View File

@@ -14,7 +14,7 @@ fn basic_auth() {
let resp = get("test://host/basic_auth") let resp = get("test://host/basic_auth")
.auth("martin", "rubbermashgum") .auth("martin", "rubbermashgum")
.call(); .call();
assert_eq!(*resp.status(), 200); assert_eq!(resp.status(), 200);
} }
#[test] #[test]
@@ -26,5 +26,5 @@ fn kind_auth() {
let resp = get("test://host/kind_auth") let resp = get("test://host/kind_auth")
.auth_kind("Digest", "abcdefgh123") .auth_kind("Digest", "abcdefgh123")
.call(); .call();
assert_eq!(*resp.status(), 200); assert_eq!(resp.status(), 200);
} }

View File

@@ -7,7 +7,7 @@ fn read_range() {
let resp = get("https://s3.amazonaws.com/foosrvr/bbb.mp4") let resp = get("https://s3.amazonaws.com/foosrvr/bbb.mp4")
.set("Range", "bytes=1000-1999") .set("Range", "bytes=1000-1999")
.call(); .call();
assert_eq!(*resp.status(), 206); assert_eq!(resp.status(), 206);
let mut reader = resp.into_reader(); let mut reader = resp.into_reader();
let mut buf = vec![]; let mut buf = vec![];
let len = reader.read_to_end(&mut buf).unwrap(); let len = reader.read_to_end(&mut buf).unwrap();
@@ -26,7 +26,7 @@ fn agent_pool() {
let resp = agent.get("https://s3.amazonaws.com/foosrvr/bbb.mp4") let resp = agent.get("https://s3.amazonaws.com/foosrvr/bbb.mp4")
.set("Range", "bytes=1000-1999") .set("Range", "bytes=1000-1999")
.call(); .call();
assert_eq!(*resp.status(), 206); assert_eq!(resp.status(), 206);
let mut reader = resp.into_reader(); let mut reader = resp.into_reader();
let mut buf = vec![]; let mut buf = vec![];
// reading the entire content will return the connection to the pool // reading the entire content will return the connection to the pool
@@ -46,7 +46,7 @@ fn agent_pool() {
let resp = agent.get("https://s3.amazonaws.com/foosrvr/bbb.mp4") let resp = agent.get("https://s3.amazonaws.com/foosrvr/bbb.mp4")
.set("Range", "bytes=5000-6999") .set("Range", "bytes=5000-6999")
.call(); .call();
assert_eq!(*resp.status(), 206); assert_eq!(resp.status(), 206);
let mut reader = resp.into_reader(); let mut reader = resp.into_reader();
let mut buf = vec![]; let mut buf = vec![];
let len = reader.read_to_end(&mut buf).unwrap(); let len = reader.read_to_end(&mut buf).unwrap();

View File

@@ -11,7 +11,7 @@ fn header_passing() {
test::make_response(200, "OK", vec!["X-Bar: foo"], vec![]) test::make_response(200, "OK", vec!["X-Bar: foo"], vec![])
}); });
let resp = get("test://host/header_passing").set("X-Foo", "bar").call(); let resp = get("test://host/header_passing").set("X-Foo", "bar").call();
assert_eq!(*resp.status(), 200); assert_eq!(resp.status(), 200);
assert!(resp.has("X-Bar")); assert!(resp.has("X-Bar"));
assert_eq!(resp.header("X-Bar").unwrap(), "foo"); assert_eq!(resp.header("X-Bar").unwrap(), "foo");
} }
@@ -27,7 +27,7 @@ fn repeat_non_x_header() {
.set("Accept", "bar") .set("Accept", "bar")
.set("Accept", "baz") .set("Accept", "baz")
.call(); .call();
assert_eq!(*resp.status(), 200); assert_eq!(resp.status(), 200);
} }
#[test] #[test]
@@ -45,7 +45,7 @@ fn repeat_x_header() {
.set("X-Forwarded-For", "130.240.19.2") .set("X-Forwarded-For", "130.240.19.2")
.set("X-Forwarded-For", "130.240.19.3") .set("X-Forwarded-For", "130.240.19.3")
.call(); .call();
assert_eq!(*resp.status(), 200); assert_eq!(resp.status(), 200);
} }
#[test] #[test]