Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow extra headers to be attached to requests #9

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
/// if response.status() == reqwest::StatusCode::NOT_MODIFIED {
/// Ok(None)
/// } else {
/// let reader = AsyncHttpRangeReader::from_head_response(client, response).await?;
/// let reader = AsyncHttpRangeReader::from_head_response(client, response, HeaderMap::default()).await?;
/// Ok(Some(reader))
/// }
/// }
Expand Down Expand Up @@ -142,6 +142,7 @@
client: impl Into<reqwest_middleware::ClientWithMiddleware>,
url: reqwest::Url,
check_method: CheckSupportMethod,
extra_headers: HeaderMap,
) -> Result<(Self, HeaderMap), AsyncHttpRangeReaderError> {
let client = client.into();
match check_method {
Expand All @@ -154,15 +155,15 @@
)
.await?;
let response_headers = response.headers().clone();
let self_ = Self::from_tail_response(client, response).await?;
let self_ = Self::from_tail_response(client, response, extra_headers).await?;
Ok((self_, response_headers))
}
CheckSupportMethod::Head => {
let response =
Self::initial_head_request(client.clone(), url.clone(), HeaderMap::default())
.await?;
let response_headers = response.headers().clone();
let self_ = Self::from_head_response(client, response).await?;
let self_ = Self::from_head_response(client, response, extra_headers).await?;
Ok((self_, response_headers))
}
}
Expand Down Expand Up @@ -198,6 +199,7 @@
pub async fn from_tail_response(
client: impl Into<reqwest_middleware::ClientWithMiddleware>,
tail_request_response: Response,
extra_headers: HeaderMap,
) -> Result<Self, AsyncHttpRangeReaderError> {
let client = client.into();

Expand Down Expand Up @@ -243,6 +245,7 @@
tokio::spawn(run_streamer(
client,
tail_request_response.url().clone(),
extra_headers,
Some((tail_request_response, start)),
memory_map,
state_tx,
Expand Down Expand Up @@ -296,6 +299,7 @@
pub async fn from_head_response(
client: impl Into<reqwest_middleware::ClientWithMiddleware>,
head_response: Response,
extra_headers: HeaderMap,
) -> Result<Self, AsyncHttpRangeReaderError> {
let client = client.into();

Expand Down Expand Up @@ -341,6 +345,7 @@
tokio::spawn(run_streamer(
client,
head_response.url().clone(),
extra_headers,
None,
memory_map,
state_tx,
Expand Down Expand Up @@ -406,6 +411,7 @@
async fn run_streamer(
client: reqwest_middleware::ClientWithMiddleware,
url: Url,
extra_headers: HeaderMap,
initial_tail_response: Option<(Response, u64)>,
mut memory_map: MmapMut,
mut state_tx: Sender<StreamerState>,
Expand Down Expand Up @@ -461,6 +467,7 @@
let response = match client
.get(url.clone())
.header(reqwest::header::RANGE, range_string)
.headers(extra_headers.clone())
.send()
.instrument(span)
.await
Expand Down Expand Up @@ -676,7 +683,7 @@
);

// Construct an AsyncRangeReader
let (mut range, _) = AsyncHttpRangeReader::new(

Check failure on line 686 in src/lib.rs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

this function takes 4 arguments but 3 arguments were supplied
Client::new(),
server.url().join("andes-1.8.3-pyhd8ed1ab_0.conda").unwrap(),
check_method,
Expand Down Expand Up @@ -770,7 +777,7 @@
let server = StaticDirectoryServer::new(&path);

// Construct an AsyncRangeReader
let (mut range, _) = AsyncHttpRangeReader::new(

Check failure on line 780 in src/lib.rs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

this function takes 4 arguments but 3 arguments were supplied
Client::new(),
server.url().join("andes-1.8.3-pyhd8ed1ab_0.conda").unwrap(),
check_method,
Expand Down Expand Up @@ -811,7 +818,7 @@
#[tokio::test]
async fn test_not_found() {
let server = StaticDirectoryServer::new(Path::new(env!("CARGO_MANIFEST_DIR")));
let err = AsyncHttpRangeReader::new(

Check failure on line 821 in src/lib.rs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

this function takes 4 arguments but 3 arguments were supplied
Client::new(),
server.url().join("not-found").unwrap(),
CheckSupportMethod::Head,
Expand Down
Loading