Gets rid of synthetic_error, and makes the various send_* methods return `Result<Response, Error>`. Introduces a new error type "HTTP", which represents an error due to status codes 4xx or 5xx. The HTTP error type contains a boxed Response, so users can read the actual response if they want. Adds an `error_for_status` setting to disable the functionality of treating 4xx and 5xx as errors. Adds .unwrap() to a lot of tests. Fixes #128.
24 lines
701 B
Rust
24 lines
701 B
Rust
#[cfg(any(feature = "tls", feature = "native-tls"))]
|
|
use std::io::Read;
|
|
|
|
#[cfg(any(feature = "tls", feature = "native-tls"))]
|
|
use super::super::*;
|
|
|
|
#[test]
|
|
#[cfg(any(feature = "tls", feature = "native-tls"))]
|
|
fn read_range() {
|
|
let resp = get("https://ureq.s3.eu-central-1.amazonaws.com/sherlock.txt")
|
|
.set("Range", "bytes=1000-1999")
|
|
.call()
|
|
.unwrap();
|
|
assert_eq!(resp.status(), 206);
|
|
let mut reader = resp.into_reader();
|
|
let mut buf = vec![];
|
|
let len = reader.read_to_end(&mut buf).unwrap();
|
|
assert_eq!(len, 1000);
|
|
assert_eq!(
|
|
&buf[0..20],
|
|
[83, 99, 111, 116, 116, 34, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32]
|
|
)
|
|
}
|