Skip to content

Commit 4c6737a

Browse files
authored
feat: Indicate range request support with Accept-Ranges header (#104)
## What I'm changing This appends the [`Accept-Ranges`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Accept-Ranges) header to GET and HEAD responses for objects, indicating support for HTTP range requests. Since some clients look for this header, it should improve use of range requests. Addresses #103. ## How I did it `get_object` and `head_object` responses now include `Accept-Ranges`, as well as `Access-Control-Expose-Headers` for CORS safelisting. ## How to test it When running the proxy: * Perform a HEAD or GET request for an object * Check the response headers; `Accept-Ranges: bytes` and `Access-Control-Expose-Headers: Accept-Ranges` should both be present ## PR Checklist - [x] This PR has **no** breaking changes. - [ ] I have updated or added new tests to cover the changes in this PR. - [ ] This PR affects the [Source Cooperative Frontend & API](https://github.com/source-cooperative/source.coop), and I have opened issue/PR #XXX to track the change. ## Related Issues [[Proposed Feature] Indicate range request support with Accept-Ranges header](#103)
1 parent f072484 commit 4c6737a

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/main.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ async fn get_object(
117117
};
118118

119119
let mut response = response
120+
.insert_header(("Accept-Ranges", "bytes"))
121+
.insert_header(("Access-Control-Expose-Headers", "Accept-Ranges"))
120122
.insert_header(("Content-Type", res.content_type))
121123
.insert_header(("Last-Modified", res.last_modified))
122124
.insert_header(("Content-Length", res.content_length.to_string()))
@@ -133,7 +135,10 @@ async fn get_object(
133135
content_length
134136
),
135137
))
136-
.insert_header(("Access-Control-Expose-Headers", "Content-Range"));
138+
.insert_header((
139+
"Access-Control-Expose-Headers",
140+
"Accept-Ranges, Content-Range",
141+
));
137142
}
138143

139144
Ok(response.body(streaming_response))
@@ -351,6 +356,8 @@ async fn head_object(
351356

352357
let res = client.head_object(key.clone()).await?;
353358
Ok(HttpResponse::Ok()
359+
.insert_header(("Accept-Ranges", "bytes"))
360+
.insert_header(("Access-Control-Expose-Headers", "Accept-Ranges"))
354361
.insert_header(("Content-Type", res.content_type))
355362
.insert_header(("Last-Modified", res.last_modified))
356363
.insert_header(("ETag", res.etag))

0 commit comments

Comments
 (0)