Skip to content

Commit 0c50afe

Browse files
authored
Upgrade http-range-header to 0.4 (#391)
1 parent 1bca37d commit 0c50afe

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

tower-http/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121

2222
## Fixed
2323

24-
- None.
24+
- Accepts range headers with ranges where the end of range goes past the end of the document by bumping
25+
http-range-header to `0.4`
2526

2627
# 0.4.2 (July 19, 2023)
2728

tower-http/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ tower-service = "0.3"
2626
# optional dependencies
2727
async-compression = { version = "0.4", optional = true, features = ["tokio"] }
2828
base64 = { version = "0.21", optional = true }
29-
http-range-header = "0.3.0"
29+
http-range-header = "0.4.0"
3030
iri-string = { version = "0.7.0", optional = true }
3131
mime = { version = "0.3.17", optional = true, default_features = false }
3232
mime_guess = { version = "2", optional = true, default_features = false }

tower-http/src/services/fs/serve_dir/tests.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use http::{Request, StatusCode};
88
use http_body::Body as HttpBody;
99
use hyper::Body;
1010
use std::convert::Infallible;
11-
use std::io::{self, Read};
11+
use std::io::Read;
1212
use tower::{service_fn, ServiceExt};
1313

1414
#[tokio::test]
@@ -480,7 +480,7 @@ async fn read_partial_in_bounds() {
480480
}
481481

482482
#[tokio::test]
483-
async fn read_partial_rejects_out_of_bounds_range() {
483+
async fn read_partial_accepts_out_of_bounds_range() {
484484
let svc = ServeDir::new("..");
485485
let bytes_start_incl = 0;
486486
let bytes_end_excl = 9999999;
@@ -496,11 +496,16 @@ async fn read_partial_rejects_out_of_bounds_range() {
496496
.unwrap();
497497
let res = svc.oneshot(req).await.unwrap();
498498

499-
assert_eq!(res.status(), StatusCode::RANGE_NOT_SATISFIABLE);
499+
assert_eq!(res.status(), StatusCode::PARTIAL_CONTENT);
500500
let file_contents = std::fs::read("../README.md").unwrap();
501+
// Out of bounds range gives all bytes
501502
assert_eq!(
502503
res.headers()["content-range"],
503-
&format!("bytes */{}", file_contents.len())
504+
&format!(
505+
"bytes 0-{}/{}",
506+
file_contents.len() - 1,
507+
file_contents.len()
508+
)
504509
)
505510
}
506511

0 commit comments

Comments
 (0)