resp.status() return u16
This commit is contained in:
@@ -67,7 +67,7 @@ impl Response {
|
||||
/// ```
|
||||
/// 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 {
|
||||
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`
|
||||
pub fn status(&self) -> &u16 {
|
||||
&self.status
|
||||
pub fn status(&self) -> u16 {
|
||||
self.status
|
||||
}
|
||||
|
||||
/// The status text: `OK`
|
||||
@@ -171,7 +171,7 @@ impl Response {
|
||||
/// assert!(resp.error());
|
||||
///
|
||||
/// // synthetic error code 400
|
||||
/// assert_eq!(*resp.status(), 400);
|
||||
/// assert_eq!(resp.status(), 400);
|
||||
///
|
||||
/// // tell that it's synthetic.
|
||||
/// assert!(resp.synthetic());
|
||||
@@ -379,7 +379,7 @@ impl Response {
|
||||
/// let read = Cursor::new(text.to_string().into_bytes());
|
||||
/// 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 {
|
||||
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 resp: Response = s.parse::<Response>().unwrap_err().into();
|
||||
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.content_type(), "text/plain");
|
||||
let v = resp.into_string().unwrap();
|
||||
|
||||
@@ -14,7 +14,7 @@ fn basic_auth() {
|
||||
let resp = get("test://host/basic_auth")
|
||||
.auth("martin", "rubbermashgum")
|
||||
.call();
|
||||
assert_eq!(*resp.status(), 200);
|
||||
assert_eq!(resp.status(), 200);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -26,5 +26,5 @@ fn kind_auth() {
|
||||
let resp = get("test://host/kind_auth")
|
||||
.auth_kind("Digest", "abcdefgh123")
|
||||
.call();
|
||||
assert_eq!(*resp.status(), 200);
|
||||
assert_eq!(resp.status(), 200);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ fn read_range() {
|
||||
let resp = get("https://s3.amazonaws.com/foosrvr/bbb.mp4")
|
||||
.set("Range", "bytes=1000-1999")
|
||||
.call();
|
||||
assert_eq!(*resp.status(), 206);
|
||||
assert_eq!(resp.status(), 206);
|
||||
let mut reader = resp.into_reader();
|
||||
let mut buf = vec![];
|
||||
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")
|
||||
.set("Range", "bytes=1000-1999")
|
||||
.call();
|
||||
assert_eq!(*resp.status(), 206);
|
||||
assert_eq!(resp.status(), 206);
|
||||
let mut reader = resp.into_reader();
|
||||
let mut buf = vec![];
|
||||
// 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")
|
||||
.set("Range", "bytes=5000-6999")
|
||||
.call();
|
||||
assert_eq!(*resp.status(), 206);
|
||||
assert_eq!(resp.status(), 206);
|
||||
let mut reader = resp.into_reader();
|
||||
let mut buf = vec![];
|
||||
let len = reader.read_to_end(&mut buf).unwrap();
|
||||
|
||||
@@ -11,7 +11,7 @@ fn header_passing() {
|
||||
test::make_response(200, "OK", vec!["X-Bar: foo"], vec![])
|
||||
});
|
||||
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_eq!(resp.header("X-Bar").unwrap(), "foo");
|
||||
}
|
||||
@@ -27,7 +27,7 @@ fn repeat_non_x_header() {
|
||||
.set("Accept", "bar")
|
||||
.set("Accept", "baz")
|
||||
.call();
|
||||
assert_eq!(*resp.status(), 200);
|
||||
assert_eq!(resp.status(), 200);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -45,7 +45,7 @@ fn repeat_x_header() {
|
||||
.set("X-Forwarded-For", "130.240.19.2")
|
||||
.set("X-Forwarded-For", "130.240.19.3")
|
||||
.call();
|
||||
assert_eq!(*resp.status(), 200);
|
||||
assert_eq!(resp.status(), 200);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user