mod fixtures; mod utils; use fixtures::{server, Error, TestServer}; use reqwest::header::HeaderValue; use rstest::rstest; #[rstest] fn get_file_range(server: TestServer) -> Result<(), Error> { let resp = fetch!(b"GET", format!("{}index.html", server.url())) .header("range", HeaderValue::from_static("bytes=0-6")) .send()?; assert_eq!(resp.status(), 206); assert_eq!(resp.headers().get("content-range").unwrap(), "bytes 0-6/18"); assert_eq!(resp.headers().get("accept-ranges").unwrap(), "bytes"); assert_eq!(resp.headers().get("content-length").unwrap(), "7"); assert_eq!(resp.text()?, "This is"); Ok(()) } #[rstest] fn get_file_range_beyond(server: TestServer) -> Result<(), Error> { let resp = fetch!(b"GET", format!("{}index.html", server.url())) .header("range", HeaderValue::from_static("bytes=12-20")) .send()?; assert_eq!(resp.status(), 416); assert_eq!(resp.headers().get("content-range").unwrap(), "bytes */18"); assert_eq!(resp.headers().get("accept-ranges").unwrap(), "bytes"); assert_eq!(resp.headers().get("content-length").unwrap(), "0"); Ok(()) } #[rstest] fn get_file_range_invalid(server: TestServer) -> Result<(), Error> { let resp = fetch!(b"GET", format!("{}index.html", server.url())) .header("range", HeaderValue::from_static("bytes=20-")) .send()?; assert_eq!(resp.status(), 416); assert_eq!(resp.headers().get("content-range").unwrap(), "bytes */18"); Ok(()) }