Skip to content

Commit

Permalink
fix: always use requested URL, rather than response URL (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored May 6, 2024
1 parent 97d0b4a commit 1aadb68
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub use error::AsyncHttpRangeReaderError;
/// if response.status() == reqwest::StatusCode::NOT_MODIFIED {
/// Ok(None)
/// } else {
/// let reader = AsyncHttpRangeReader::from_head_response(client, response, HeaderMap::default()).await?;
/// let reader = AsyncHttpRangeReader::from_head_response(client, response, url, HeaderMap::default()).await?;
/// Ok(Some(reader))
/// }
/// }
Expand Down Expand Up @@ -141,7 +141,7 @@ impl AsyncHttpRangeReader {
/// Construct a new `AsyncHttpRangeReader`.
pub async fn new(
client: impl Into<reqwest_middleware::ClientWithMiddleware>,
url: reqwest::Url,
url: Url,
check_method: CheckSupportMethod,
extra_headers: HeaderMap,
) -> Result<(Self, HeaderMap), AsyncHttpRangeReaderError> {
Expand All @@ -156,15 +156,15 @@ impl AsyncHttpRangeReader {
)
.await?;
let response_headers = response.headers().clone();
let self_ = Self::from_tail_response(client, response, extra_headers).await?;
let self_ = Self::from_tail_response(client, response, url, 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, extra_headers).await?;
let self_ = Self::from_head_response(client, response, url, extra_headers).await?;
Ok((self_, response_headers))
}
}
Expand Down Expand Up @@ -200,6 +200,7 @@ impl AsyncHttpRangeReader {
pub async fn from_tail_response(
client: impl Into<reqwest_middleware::ClientWithMiddleware>,
tail_request_response: Response,
url: Url,
extra_headers: HeaderMap,
) -> Result<Self, AsyncHttpRangeReaderError> {
let client = client.into();
Expand Down Expand Up @@ -245,7 +246,7 @@ impl AsyncHttpRangeReader {
let (state_tx, state_rx) = watch::channel(StreamerState::default());
tokio::spawn(run_streamer(
client,
tail_request_response.url().clone(),
url,
extra_headers,
Some((tail_request_response, start)),
memory_map,
Expand Down Expand Up @@ -300,6 +301,7 @@ impl AsyncHttpRangeReader {
pub async fn from_head_response(
client: impl Into<reqwest_middleware::ClientWithMiddleware>,
head_response: Response,
url: Url,
extra_headers: HeaderMap,
) -> Result<Self, AsyncHttpRangeReaderError> {
let client = client.into();
Expand Down Expand Up @@ -345,7 +347,7 @@ impl AsyncHttpRangeReader {
let (state_tx, state_rx) = watch::channel(StreamerState::default());
tokio::spawn(run_streamer(
client,
head_response.url().clone(),
url,
extra_headers,
None,
memory_map,
Expand Down Expand Up @@ -730,7 +732,7 @@ mod test {
);

// Prefetch the data for the metadata.json file
let entry = reader.file().entries().get(0).unwrap();
let entry = reader.file().entries().first().unwrap();
let offset = entry.header_offset();
// Get the size of the entry plus the header + size of the filename. We should also actually
// include bytes for the extra fields but we don't have that information.
Expand Down

0 comments on commit 1aadb68

Please sign in to comment.