Skip to content

Commit

Permalink
Upgrade http-range-header to 0.4 (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusGrass authored Jul 21, 2023
1 parent 1bca37d commit 0c50afe
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion tower-http/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tower-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
13 changes: 9 additions & 4 deletions tower-http/src/services/fs/serve_dir/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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;
Expand All @@ -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()
)
)
}

Expand Down

0 comments on commit 0c50afe

Please sign in to comment.