From 0c50afe28a3c9bec7aa4e1f620ce5a0a805b6103 Mon Sep 17 00:00:00 2001 From: MarcusGrass <34198073+MarcusGrass@users.noreply.github.com> Date: Fri, 21 Jul 2023 17:32:17 +0200 Subject: [PATCH] Upgrade http-range-header to 0.4 (#391) --- tower-http/CHANGELOG.md | 3 ++- tower-http/Cargo.toml | 2 +- tower-http/src/services/fs/serve_dir/tests.rs | 13 +++++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tower-http/CHANGELOG.md b/tower-http/CHANGELOG.md index 3c4b959f..2581d9b6 100644 --- a/tower-http/CHANGELOG.md +++ b/tower-http/CHANGELOG.md @@ -21,7 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Fixed -- None. +- Accepts range headers with ranges where the end of range goes past the end of the document by bumping +http-range-header to `0.4` # 0.4.2 (July 19, 2023) diff --git a/tower-http/Cargo.toml b/tower-http/Cargo.toml index 5d723862..26caaf4c 100644 --- a/tower-http/Cargo.toml +++ b/tower-http/Cargo.toml @@ -26,7 +26,7 @@ tower-service = "0.3" # optional dependencies async-compression = { version = "0.4", optional = true, features = ["tokio"] } base64 = { version = "0.21", optional = true } -http-range-header = "0.3.0" +http-range-header = "0.4.0" iri-string = { version = "0.7.0", optional = true } mime = { version = "0.3.17", optional = true, default_features = false } mime_guess = { version = "2", optional = true, default_features = false } diff --git a/tower-http/src/services/fs/serve_dir/tests.rs b/tower-http/src/services/fs/serve_dir/tests.rs index 9a25c6dd..eb870d4a 100644 --- a/tower-http/src/services/fs/serve_dir/tests.rs +++ b/tower-http/src/services/fs/serve_dir/tests.rs @@ -8,7 +8,7 @@ use http::{Request, StatusCode}; use http_body::Body as HttpBody; use hyper::Body; use std::convert::Infallible; -use std::io::{self, Read}; +use std::io::Read; use tower::{service_fn, ServiceExt}; #[tokio::test] @@ -480,7 +480,7 @@ async fn read_partial_in_bounds() { } #[tokio::test] -async fn read_partial_rejects_out_of_bounds_range() { +async fn read_partial_accepts_out_of_bounds_range() { let svc = ServeDir::new(".."); let bytes_start_incl = 0; let bytes_end_excl = 9999999; @@ -496,11 +496,16 @@ async fn read_partial_rejects_out_of_bounds_range() { .unwrap(); let res = svc.oneshot(req).await.unwrap(); - assert_eq!(res.status(), StatusCode::RANGE_NOT_SATISFIABLE); + assert_eq!(res.status(), StatusCode::PARTIAL_CONTENT); let file_contents = std::fs::read("../README.md").unwrap(); + // Out of bounds range gives all bytes assert_eq!( res.headers()["content-range"], - &format!("bytes */{}", file_contents.len()) + &format!( + "bytes 0-{}/{}", + file_contents.len() - 1, + file_contents.len() + ) ) }