Skip to content

Commit 1400918

Browse files
authored
Allow extra headers to be attached to requests (#9)
1 parent 6021c6c commit 1400918

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub use error::AsyncHttpRangeReaderError;
7171
/// if response.status() == reqwest::StatusCode::NOT_MODIFIED {
7272
/// Ok(None)
7373
/// } else {
74-
/// let reader = AsyncHttpRangeReader::from_head_response(client, response).await?;
74+
/// let reader = AsyncHttpRangeReader::from_head_response(client, response, HeaderMap::default()).await?;
7575
/// Ok(Some(reader))
7676
/// }
7777
/// }
@@ -142,6 +142,7 @@ impl AsyncHttpRangeReader {
142142
client: impl Into<reqwest_middleware::ClientWithMiddleware>,
143143
url: reqwest::Url,
144144
check_method: CheckSupportMethod,
145+
extra_headers: HeaderMap,
145146
) -> Result<(Self, HeaderMap), AsyncHttpRangeReaderError> {
146147
let client = client.into();
147148
match check_method {
@@ -154,15 +155,15 @@ impl AsyncHttpRangeReader {
154155
)
155156
.await?;
156157
let response_headers = response.headers().clone();
157-
let self_ = Self::from_tail_response(client, response).await?;
158+
let self_ = Self::from_tail_response(client, response, extra_headers).await?;
158159
Ok((self_, response_headers))
159160
}
160161
CheckSupportMethod::Head => {
161162
let response =
162163
Self::initial_head_request(client.clone(), url.clone(), HeaderMap::default())
163164
.await?;
164165
let response_headers = response.headers().clone();
165-
let self_ = Self::from_head_response(client, response).await?;
166+
let self_ = Self::from_head_response(client, response, extra_headers).await?;
166167
Ok((self_, response_headers))
167168
}
168169
}
@@ -198,6 +199,7 @@ impl AsyncHttpRangeReader {
198199
pub async fn from_tail_response(
199200
client: impl Into<reqwest_middleware::ClientWithMiddleware>,
200201
tail_request_response: Response,
202+
extra_headers: HeaderMap,
201203
) -> Result<Self, AsyncHttpRangeReaderError> {
202204
let client = client.into();
203205

@@ -243,6 +245,7 @@ impl AsyncHttpRangeReader {
243245
tokio::spawn(run_streamer(
244246
client,
245247
tail_request_response.url().clone(),
248+
extra_headers,
246249
Some((tail_request_response, start)),
247250
memory_map,
248251
state_tx,
@@ -296,6 +299,7 @@ impl AsyncHttpRangeReader {
296299
pub async fn from_head_response(
297300
client: impl Into<reqwest_middleware::ClientWithMiddleware>,
298301
head_response: Response,
302+
extra_headers: HeaderMap,
299303
) -> Result<Self, AsyncHttpRangeReaderError> {
300304
let client = client.into();
301305

@@ -341,6 +345,7 @@ impl AsyncHttpRangeReader {
341345
tokio::spawn(run_streamer(
342346
client,
343347
head_response.url().clone(),
348+
extra_headers,
344349
None,
345350
memory_map,
346351
state_tx,
@@ -406,6 +411,7 @@ impl AsyncHttpRangeReader {
406411
async fn run_streamer(
407412
client: reqwest_middleware::ClientWithMiddleware,
408413
url: Url,
414+
extra_headers: HeaderMap,
409415
initial_tail_response: Option<(Response, u64)>,
410416
mut memory_map: MmapMut,
411417
mut state_tx: Sender<StreamerState>,
@@ -461,6 +467,7 @@ async fn run_streamer(
461467
let response = match client
462468
.get(url.clone())
463469
.header(reqwest::header::RANGE, range_string)
470+
.headers(extra_headers.clone())
464471
.send()
465472
.instrument(span)
466473
.await

0 commit comments

Comments
 (0)