feat: Add Response::is_success utility method
This commit is contained in:
		
							parent
							
								
									415e930a07
								
							
						
					
					
						commit
						bd726c7d4c
					
				
					 2 changed files with 9 additions and 1 deletions
				
			
		| 
						 | 
					@ -303,6 +303,14 @@ impl <'a> Request<'a> {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl <T> Response<T> {
 | 
				
			||||||
 | 
					    /// Check whether the status code of this HTTP response is a
 | 
				
			||||||
 | 
					    /// success (i.e. in the 200-299 range).
 | 
				
			||||||
 | 
					    pub fn is_success(&self) -> bool {
 | 
				
			||||||
 | 
					        self.status >= 200 && self.status < 300
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl Response<Vec<u8>> {
 | 
					impl Response<Vec<u8>> {
 | 
				
			||||||
    /// Attempt to parse the HTTP response body as a UTF-8 encoded
 | 
					    /// Attempt to parse the HTTP response body as a UTF-8 encoded
 | 
				
			||||||
    /// string.
 | 
					    /// string.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,7 +9,7 @@ fn test_http_get() {
 | 
				
			||||||
    let resp = Request::new(Method::Get, "https://httpbin.org/get")
 | 
					    let resp = Request::new(Method::Get, "https://httpbin.org/get")
 | 
				
			||||||
        .send().expect("failed to send request");
 | 
					        .send().expect("failed to send request");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    assert_eq!(200, resp.status, "response status should be 200 OK");
 | 
					    assert!(resp.is_success(), "request should have succeeded");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[test]
 | 
					#[test]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue