Repository: static-web-server/static-web-server (language: rust)

Issue:
Configuration advanced.headers is not applied when html served though 'index-files' matching
### Search for duplicate issues

- [X] I already searched, and this issue is not a duplicate.

### Issue scope

Configuration (e.g. TOML)

### Describe the bug

As described by title, this seems to be a bug, as use of index file is so common. Nginx uses MIME type or scripting with `$request_filename` to match custom header rules, so it doesn't have such issue.

### How to reproduce it

1. Prepare configuration file config.toml.
```toml
# ...
directory-listing = true
index-files = "index.html"

[advanced]

[[advanced.headers]]
source = "**/*.{html,js,css,png,ico,json,xml}"
headers = { Cross-Origin-Embedder-Policy = "require-corp", Cross-Origin-Opener-Policy = "same-origin" }
```
2. Start server with command `static-web-server -w config.toml`.
3. Open a browser tab, access a directory which contains index.html, open another browser tab, access the previously matched index file with explicit path, e.g. "/index.html".
4. Compare response headers of the two requests, you may see the response of directory index-matching doesn't contain CORP headers.

### Expected behavior

When matching index files, actual requested file name SHOULD be used to match '[[advanced.headers]] souce' instead of the original request uri.

By the way, resources served though "directory-listing" MAY be assumed to have a default file name and an extension of the "directory-listing-format" option value, e.g. "directory-listing.html", thus to match rules in the "[[advanced.headers]]" section.

### Complementary information

_No response_

### Build target

x86_64-pc-windows-msvc

### Environment and specs

- [ ] **static-web-server:** 2.28.0
- [ ] **OS:** Windows 10
- [ ] **Arch:** x86_64 (64-bit)
- [ ] **Docker:**
- [ ] **Client:** Chrome 123
- [ ] Specify others


### Additional context

_No response_


Discussion / hints:

Fix patch:
diff --git a/src/custom_headers.rs b/src/custom_headers.rs
index b9a608f1..b5fbd206 100644
--- a/src/custom_headers.rs
+++ b/src/custom_headers.rs
@@ -7,12 +7,34 @@
 //!
 
 use hyper::{Body, Response};
+use std::{ffi::OsStr, path::PathBuf};
 
 use crate::settings::Headers;
 
 /// Append custom HTTP headers to current response.
-pub fn append_headers(uri_path: &str, headers_opts: Option<&[Headers]>, resp: &mut Response<Body>) {
+pub fn append_headers(
+    uri_path: &str,
+    headers_opts: Option<&[Headers]>,
+    resp: &mut Response<Body>,
+    file_path: Option<&PathBuf>,
+) {
     if let Some(headers_vec) = headers_opts {
+        let mut uri_path_auto_index = None;
+        if file_path.is_some() && uri_path.ends_with('/') {
+            if let Some(name) = file_path.unwrap().file_name().and_then(OsStr::to_str) {
+                if uri_path == "/" {
+                    uri_path_auto_index = Some([uri_path, name].concat())
+                } else {
+                    uri_path_auto_index = Some([uri_path, "/", name].concat())
+                }
+            }
+        }
+
+        let uri_path = match uri_path_auto_index {
+            Some(ref s) => s.as_str(),
+            _ => uri_path,
+        };
+
         for headers_entry in headers_vec.iter() {
             // Match header glob pattern against request uri
             if headers_entry.source.is_match(uri_path) {
diff --git a/src/handler.rs b/src/handler.rs
index 277b484a..08a7c99a 100644
--- a/src/handler.rs
+++ b/src/handler.rs
@@ -442,7 +442,10 @@ impl RequestHandler {
             })
             .await
             {
-                Ok((mut resp, _is_precompressed)) => {
+                Ok(result) => {
+                    let _is_precompressed = result.is_precompressed;
+                    let mut resp = result.resp;
+
                     // Append CORS headers if they are present
                     if let Some(cors_headers) = cors_headers {
                         if !cors_headers.is_empty() {
@@ -496,6 +499,7 @@ impl RequestHandler {
                             uri_path,
                             advanced.headers.as_deref(),
                             &mut resp,
+                            Some(&result.file_path),
                         )
                     }
 
@@ -564,6 +568,7 @@ impl RequestHandler {
                                 uri_path,
                                 advanced.headers.as_deref(),
                                 &mut resp,
+                                None,
                             )
                         }
 
diff --git a/src/static_files.rs b/src/static_files.rs
index e788e257..1103eee5 100644
--- a/src/static_files.rs
+++ b/src/static_files.rs
@@ -72,9 +72,19 @@ pub struct HandleOpts<'a> {
     pub ignore_hidden_files: bool,
 }
 
+/// Static file response type with additional data.
+pub struct StaticFileResponse {
+    /// Inner HTTP response.
+    pub resp: Response<Body>,
+    /// If the inner HTTP response is already pre-compressed.
+    pub is_precompressed: bool,
+    /// The file path of the inner HTTP response.
+    pub file_path: PathBuf,
+}
+
 /// The server entry point to handle incoming requests which map to specific files
 /// on file system and return a file response.
-pub async fn handle<'a>(opts: &HandleOpts<'a>) -> Result<(Response<Body>, bool), StatusCode> {
+pub async fn handle<'a>(opts: &HandleOpts<'a>) -> Result<StaticFileResponse, StatusCode> {
     let method = opts.method;
     let uri_path = opts.uri_path;
 
@@ -104,6 +114,8 @@ pub async fn handle<'a>(opts: &HandleOpts<'a>) -> Result<(Response<Body>, bool),
         return Err(StatusCode::NOT_FOUND);
     }
 
+    let resp_file_path = file_path.to_owned();
+
     // `is_precompressed` relates to `opts.compression_static` value
     let is_precompressed = precompressed_variant.is_some();
 
@@ -124,7 +136,11 @@ pub async fn handle<'a>(opts: &HandleOpts<'a>) -> Result<(Response<Body>, bool),
         *resp.status_mut() = StatusCode::PERMANENT_REDIRECT;
 
         tracing::trace!("uri doesn't end with a slash so redirecting permanently");
-        return Ok((resp, is_precompressed));
+        return Ok(StaticFileResponse {
+            resp,
+            is_precompressed,
+            file_path: resp_file_path,
+        });
     }
 
     // Respond with the permitted communication methods
@@ -135,7 +151,11 @@ pub async fn handle<'a>(opts: &HandleOpts<'a>) -> Result<(Response<Body>, bool),
             .typed_insert(headers::Allow::from_iter(HTTP_SUPPORTED_METHODS.clone()));
         resp.headers_mut().typed_insert(AcceptRanges::bytes());
 
-        return Ok((resp, is_precompressed));
+        return Ok(StaticFileResponse {
+            resp,
+            is_precompressed,
+            file_path: resp_file_path,
+        });
     }
 
     // Directory listing
@@ -155,7 +175,11 @@ pub async fn handle<'a>(opts: &HandleOpts<'a>) -> Result<(Response<Body>, bool),
         })
         .await?;
 
-        return Ok((resp, is_precompressed));
+        return Ok(StaticFileResponse {
+            resp,
+            is_precompressed,
+            file_path: resp_file_path,
+        });
     }
 
     // Check for a pre-compressed file variant if present under the `opts.compression_static` context
@@ -168,12 +192,20 @@ pub async fn handle<'a>(opts: &HandleOpts<'a>) -> Result<(Response<Body>, bool),
         resp.headers_mut()
             .insert(CONTENT_ENCODING, precomp_ext.parse().unwrap());
 
-        return Ok((resp, is_precompressed));
+        return Ok(StaticFileResponse {
+            resp,
+            is_precompressed,
+            file_path: resp_file_path,
+        });
     }
 
     let resp = file_reply(headers_opt, file_path, &metadata, None).await?;
 
-    Ok((resp, is_precompressed))
+    Ok(StaticFileResponse {
+        resp,
+        is_precompressed,
+        file_path: resp_file_path,
+    })
 }
 
 /// It defines a composed file metadata structure containing the current file


Test patch:
diff --git a/tests/compression_static.rs b/tests/compression_static.rs
index f614c6cb..ebf691ae 100644
--- a/tests/compression_static.rs
+++ b/tests/compression_static.rs
@@ -32,7 +32,7 @@ mod tests {
         std::fs::copy(&index_gz_path, &index_gz_path_public)
             .expect("unexpected error copying fixture file");
 
-        let (mut resp, _) = static_files::handle(&HandleOpts {
+        let result = static_files::handle(&HandleOpts {
             method: &Method::GET,
             headers: &headers,
             base_path: &public_dir(),
@@ -52,6 +52,7 @@ mod tests {
         })
         .await
         .expect("unexpected error response on `handle` function");
+        let mut res = result.resp;
 
         let index_gz_buf =
             std::fs::read(&index_gz_path).expect("unexpected error when reading index.html.gz");
@@ -59,9 +60,9 @@ mod tests {
 
         std::fs::remove_file(index_gz_path_public).unwrap();
 
-        let headers = resp.headers();
+        let headers = res.headers();
 
-        assert_eq!(resp.status(), 200);
+        assert_eq!(res.status(), 200);
         assert!(!headers.contains_key("content-length"));
         assert_eq!(headers["content-encoding"], "gzip");
         assert_eq!(headers["accept-ranges"], "bytes");
@@ -71,7 +72,7 @@ mod tests {
             "content-type is not html"
         );
 
-        let body = hyper::body::to_bytes(resp.body_mut())
+        let body = hyper::body::to_bytes(res.body_mut())
             .await
             .expect("unexpected bytes error during `body` conversion");
 
@@ -91,7 +92,7 @@ mod tests {
 
         let index_path_public = public_dir().join("assets/index.html");
 
-        let (mut resp, _) = static_files::handle(&HandleOpts {
+        let result = static_files::handle(&HandleOpts {
             method: &Method::GET,
             headers: &headers,
             base_path: &public_dir().join("assets/"),
@@ -111,14 +112,15 @@ mod tests {
         })
         .await
         .expect("unexpected error response on `handle` function");
+        let mut res = result.resp;
 
         let index_buf =
             std::fs::read(&index_path_public).expect("unexpected error when reading index.html");
         let index_buf = Bytes::from(index_buf);
 
-        let headers = resp.headers();
+        let headers = res.headers();
 
-        assert_eq!(resp.status(), 200);
+        assert_eq!(res.status(), 200);
         assert!(headers.contains_key("content-length"));
         assert_eq!(headers["accept-ranges"], "bytes");
         assert!(!headers["last-modified"].is_empty());
@@ -127,7 +129,7 @@ mod tests {
             "content-type is not html"
         );
 
-        let body = hyper::body::to_bytes(resp.body_mut())
+        let body = hyper::body::to_bytes(res.body_mut())
             .await
             .expect("unexpected bytes error during `body` conversion");
 
@@ -148,7 +150,7 @@ mod tests {
 
         let base_path = PathBuf::from(".");
 
-        let (_resp, _) = static_files::handle(&HandleOpts {
+        static_files::handle(&HandleOpts {
             method: &Method::GET,
             headers: &headers,
             base_path: &base_path,
diff --git a/tests/dir_listing.rs b/tests/dir_listing.rs
index 851b089b..eef69f38 100644
--- a/tests/dir_listing.rs
+++ b/tests/dir_listing.rs
@@ -53,7 +53,8 @@ mod tests {
             })
             .await
             {
-                Ok((res, _)) => {
+                Ok(result) => {
+                    let res = result.resp;
                     assert_eq!(res.status(), 308);
                     assert_eq!(res.headers()["location"], "/assets/");
                 }
@@ -84,7 +85,8 @@ mod tests {
             })
             .await
             {
-                Ok((mut res, _)) => {
+                Ok(result) => {
+                    let mut res = result.resp;
                     assert_eq!(res.status(), 200);
                     assert_eq!(res.headers()["content-type"], "text/html; charset=utf-8");
 
@@ -125,7 +127,8 @@ mod tests {
             })
             .await
             {
-                Ok((mut res, _)) => {
+                Ok(result) => {
+                    let mut res = result.resp;
                     assert_eq!(res.status(), 200);
                     assert_eq!(res.headers()["content-type"], "text/html; charset=utf-8");
 
@@ -166,7 +169,8 @@ mod tests {
             })
             .await
             {
-                Ok((res, _)) => {
+                Ok(result) => {
+                    let res = result.resp;
                     assert_eq!(res.status(), 200);
                     assert_eq!(res.headers()["content-type"], "text/markdown");
                 }
@@ -197,7 +201,8 @@ mod tests {
             })
             .await
             {
-                Ok((mut res, _)) => {
+                Ok(result) => {
+                    let mut res = result.resp;
                     assert_eq!(res.status(), 200);
                     assert_eq!(res.headers()["content-type"], "text/html; charset=utf-8");
 
@@ -249,7 +254,8 @@ mod tests {
             })
             .await
             {
-                Ok((mut res, _)) => {
+                Ok(result) => {
+                    let mut res = result.resp;
                     assert_eq!(res.status(), 200);
                     assert_eq!(res.headers()["content-type"], "application/json");
 
@@ -319,7 +325,8 @@ mod tests {
             })
             .await
             {
-                Ok((mut res, _)) => {
+                Ok(result) => {
+                    let mut res = result.resp;
                     assert_eq!(res.status(), 200);
                     assert_eq!(res.headers()["content-type"], "application/json");
 
@@ -362,7 +369,8 @@ mod tests {
             })
             .await
             {
-                Ok((mut res, _)) => {
+                Ok(result) => {
+                    let mut res = result.resp;
                     assert_eq!(res.status(), 200);
                     assert_eq!(res.headers()["content-type"], "text/html; charset=utf-8");
 
diff --git a/tests/fixtures/toml/handler.toml b/tests/fixtures/toml/handler.toml
new file mode 100644
index 00000000..a1afdbdf
--- /dev/null
+++ b/tests/fixtures/toml/handler.toml
@@ -0,0 +1,9 @@
+[general]
+
+root = "docker/public"
+
+[advanced]
+
+[[advanced.headers]]
+source = "**/*.{html,htm}"
+headers = { Server = "Static Web Server" }
diff --git a/tests/handler.rs b/tests/handler.rs
new file mode 100644
index 00000000..dda7e9d1
--- /dev/null
+++ b/tests/handler.rs
@@ -0,0 +1,66 @@
+#![forbid(unsafe_code)]
+#![deny(warnings)]
+#![deny(rust_2018_idioms)]
+#![deny(dead_code)]
+
+pub mod tests {
+    use headers::HeaderValue;
+    use hyper::Request;
+    use std::net::SocketAddr;
+
+    use static_web_server::testing::fixtures::{fixture_req_handler, REMOTE_ADDR};
+
+    #[tokio::test]
+    async fn custom_headers_apply_for_dir() {
+        let req_handler = fixture_req_handler("toml/handler.toml");
+        let remote_addr = Some(REMOTE_ADDR.parse::<SocketAddr>().unwrap());
+
+        let mut req = Request::default();
+        *req.method_mut() = hyper::Method::GET;
+        *req.uri_mut() = "http://localhost/".parse().unwrap();
+
+        match req_handler.handle(&mut req, remote_addr).await {
+            Ok(res) => {
+                assert_eq!(res.status(), 200);
+                assert_eq!(
+                    res.headers().get("content-type"),
+                    Some(&HeaderValue::from_static("text/html"))
+                );
+                assert_eq!(
+                    res.headers().get("server"),
+                    Some(&HeaderValue::from_static("Static Web Server"))
+                );
+            }
+            Err(err) => {
+                panic!("unexpected error: {err}")
+            }
+        };
+    }
+
+    #[tokio::test]
+    async fn custom_headers_apply_for_file() {
+        let req_handler = fixture_req_handler("toml/handler.toml");
+        let remote_addr = Some(REMOTE_ADDR.parse::<SocketAddr>().unwrap());
+
+        let mut req = Request::default();
+        *req.method_mut() = hyper::Method::GET;
+        *req.uri_mut() = "http://localhost/assets/index.html".parse().unwrap();
+
+        match req_handler.handle(&mut req, remote_addr).await {
+            Ok(res) => {
+                assert_eq!(res.status(), 200);
+                assert_eq!(
+                    res.headers().get("content-type"),
+                    Some(&HeaderValue::from_static("text/html"))
+                );
+                assert_eq!(
+                    res.headers().get("server"),
+                    Some(&HeaderValue::from_static("Static Web Server"))
+                );
+            }
+            Err(err) => {
+                panic!("unexpected error: {err}")
+            }
+        };
+    }
+}
diff --git a/tests/static_files.rs b/tests/static_files.rs
index b7e0c74b..4fc022c4 100644
--- a/tests/static_files.rs
+++ b/tests/static_files.rs
@@ -24,7 +24,7 @@ mod tests {
 
     #[tokio::test]
     async fn handle_file() {
-        let (mut res, _) = static_files::handle(&HandleOpts {
+        let result = static_files::handle(&HandleOpts {
             method: &Method::GET,
             headers: &HeaderMap::new(),
             base_path: &root_dir(),
@@ -43,6 +43,7 @@ mod tests {
         })
         .await
         .expect("unexpected error response on `handle` function");
+        let mut res = result.resp;
 
         let buf = fs::read(root_dir().join("index.html"))
             .expect("unexpected error during index.html reading");
@@ -66,7 +67,7 @@ mod tests {
 
     #[tokio::test]
     async fn handle_file_head() {
-        let (mut res, _) = static_files::handle(&HandleOpts {
+        let result = static_files::handle(&HandleOpts {
             method: &Method::HEAD,
             headers: &HeaderMap::new(),
             base_path: &root_dir(),
@@ -85,6 +86,7 @@ mod tests {
         })
         .await
         .expect("unexpected error response on `handle` function");
+        let mut res = result.resp;
 
         let buf = fs::read(root_dir().join("index.html"))
             .expect("unexpected error during index.html reading");
@@ -140,7 +142,7 @@ mod tests {
 
     #[tokio::test]
     async fn handle_trailing_slash_redirection() {
-        let (mut res, _) = static_files::handle(&HandleOpts {
+        let result = static_files::handle(&HandleOpts {
             method: &Method::GET,
             headers: &HeaderMap::new(),
             base_path: &root_dir(),
@@ -159,6 +161,7 @@ mod tests {
         })
         .await
         .expect("unexpected error response on `handle` function");
+        let mut res = result.resp;
 
         assert_eq!(res.status(), 308);
         assert_eq!(res.headers()["location"], "assets/");
@@ -191,7 +194,8 @@ mod tests {
         })
         .await
         {
-            Ok((res, _)) => {
+            Ok(result) => {
+                let res = result.resp;
                 assert_eq!(res.status(), 308);
                 assert_eq!(res.headers()["location"], "assets/");
             }
@@ -222,7 +226,8 @@ mod tests {
         })
         .await
         {
-            Ok((res, _)) => {
+            Ok(result) => {
+                let res = result.resp;
                 assert_eq!(res.status(), 200);
             }
             Err(status) => {
@@ -258,7 +263,8 @@ mod tests {
                 })
                 .await
                 {
-                    Ok((mut res, _)) => {
+                    Ok(result) => {
+                        let mut res = result.resp;
                         if uri.is_empty() {
                             // it should redirect permanently
                             assert_eq!(res.status(), 308);
@@ -309,7 +315,8 @@ mod tests {
             })
             .await
             {
-                Ok((res, _)) => {
+                Ok(result) => {
+                    let res = result.resp;
                     assert_eq!(res.status(), 200);
                     assert_eq!(res.headers()["content-length"], buf.len().to_string());
                 }
@@ -378,7 +385,8 @@ mod tests {
             })
             .await
             {
-                Ok((res, _)) => {
+                Ok(result) => {
+                    let res = result.resp;
                     assert_eq!(res.status(), 200);
                     assert_eq!(res.headers()["content-length"], buf.len().to_string());
                     res
@@ -414,7 +422,8 @@ mod tests {
             })
             .await
             {
-                Ok((mut res, _)) => {
+                Ok(result) => {
+                    let mut res = result.resp;
                     assert_eq!(res.status(), 304);
                     assert_eq!(res.headers().get("content-length"), None);
                     let body = hyper::body::to_bytes(res.body_mut())
@@ -453,7 +462,8 @@ mod tests {
             })
             .await
             {
-                Ok((mut res, _)) => {
+                Ok(result) => {
+                    let mut res = result.resp;
                     assert_eq!(res.status(), 200);
                     let body = hyper::body::to_bytes(res.body_mut())
                         .await
@@ -490,7 +500,8 @@ mod tests {
             })
             .await
             {
-                Ok((res, _)) => {
+                Ok(result) => {
+                    let res = result.resp;
                     assert_eq!(res.status(), 200);
                     res
                 }
@@ -525,7 +536,8 @@ mod tests {
             })
             .await
             {
-                Ok((res, _)) => {
+                Ok(result) => {
+                    let res = result.resp;
                     assert_eq!(res.status(), 200);
                 }
                 Err(_) => {
@@ -559,7 +571,8 @@ mod tests {
             })
             .await
             {
-                Ok((mut res, _)) => {
+                Ok(result) => {
+                    let mut res = result.resp;
                     assert_eq!(res.status(), 412);
 
                     let body = hyper::body::to_bytes(res.body_mut())
@@ -607,9 +620,10 @@ mod tests {
             })
             .await
             {
-                Ok((mut res, _)) => match method {
+                Ok(result) => match method {
                     // The handle only accepts HEAD or GET request methods
                     Method::GET | Method::HEAD => {
+                        let mut res = result.resp;
                         let buf = fs::read(root_dir().join("index.html"))
                             .expect("unexpected error during index.html reading");
                         let buf = Bytes::from(buf);
@@ -669,7 +683,8 @@ mod tests {
             })
             .await
             {
-                Ok((res, _)) => {
+                Ok(result) => {
+                    let res = result.resp;
                     let res = compression::auto(method, &headers, res)
                         .expect("unexpected bytes error during body compression");
 
@@ -733,7 +748,8 @@ mod tests {
             })
             .await
             {
-                Ok((mut res, _)) => {
+                Ok(result) => {
+                    let mut res = result.resp;
                     assert_eq!(res.status(), 206);
                     assert_eq!(
                         res.headers()["content-range"],
@@ -781,7 +797,8 @@ mod tests {
             })
             .await
             {
-                Ok((mut res, _)) => {
+                Ok(result) => {
+                    let mut res = result.resp;
                     assert_eq!(res.status(), 206);
                     assert_eq!(
                         res.headers()["content-range"],
@@ -829,7 +846,8 @@ mod tests {
             })
             .await
             {
-                Ok((mut res, _)) => {
+                Ok(result) => {
+                    let mut res = result.resp;
                     assert_eq!(res.status(), 206);
                     assert_eq!(
                         res.headers()["content-range"],
@@ -878,7 +896,8 @@ mod tests {
             })
             .await
             {
-                Ok((res, _)) => {
+                Ok(result) => {
+                    let res = result.resp;
                     assert_eq!(res.status(), 200);
                     assert_eq!(res.headers()["content-length"], buf.len().to_string());
                     assert_eq!(res.headers().get("content-range"), None);
@@ -919,7 +938,8 @@ mod tests {
             })
             .await
             {
-                Ok((mut res, _)) => {
+                Ok(result) => {
+                    let mut res = result.resp;
                     assert_eq!(res.status(), 206);
                     assert_eq!(
                         res.headers()["content-range"],
@@ -970,7 +990,8 @@ mod tests {
             })
             .await
             {
-                Ok((mut res, _)) => {
+                Ok(result) => {
+                    let mut res = result.resp;
                     assert_eq!(res.status(), 206);
                     assert_eq!(
                         res.headers()["content-range"],
@@ -1018,7 +1039,8 @@ mod tests {
             })
             .await
             {
-                Ok((mut res, _)) => {
+                Ok(result) => {
+                    let mut res = result.resp;
                     assert_eq!(res.status(), 416);
                     assert_eq!(
                         res.headers()["content-range"],
@@ -1066,7 +1088,8 @@ mod tests {
             })
             .await
             {
-                Ok((mut res, _)) => {
+                Ok(result) => {
+                    let mut res = result.resp;
                     assert_eq!(res.status(), 416);
                     assert_eq!(
                         res.headers()["content-range"],
@@ -1117,7 +1140,8 @@ mod tests {
             })
             .await
             {
-                Ok((mut res, _)) => {
+                Ok(result) => {
+                    let mut res = result.resp;
                     assert_eq!(res.status(), 200);
                     assert!(res.headers().get("content-length").is_some());
                     let body = hyper::body::to_bytes(res.body_mut())
@@ -1158,7 +1182,8 @@ mod tests {
             })
             .await
             {
-                Ok((res, _)) => {
+                Ok(result) => {
+                    let res = result.resp;
                     assert_eq!(res.status(), 416);
                 }
                 Err(_) => {
@@ -1198,7 +1223,8 @@ mod tests {
             })
             .await
             {
-                Ok((mut res, _)) => {
+                Ok(result) => {
+                    let mut res = result.resp;
                     assert_eq!(res.status(), 206);
                     assert_eq!(
                         res.headers()["content-range"],
@@ -1253,7 +1279,8 @@ mod tests {
             })
             .await
             {
-                Ok((mut res, _)) => {
+                Ok(result) => {
+                    let mut res = result.resp;
                     assert_eq!(res.status(), 206);
                     assert_eq!(
                         res.headers()["content-range"],
@@ -1339,7 +1366,8 @@ mod tests {
             })
             .await
             {
-                Ok((mut res, _)) => {
+                Ok(result) => {
+                    let mut res = result.resp;
                     assert_eq!(res.status(), 200);
                     assert_eq!(res.headers()["content-length"], format!("{}", buf.len()));
                     let body = hyper::body::to_bytes(res.body_mut())