Skip to content

Commit

Permalink
Merge pull request #1659 from tottoto/replace-hyperx-with-headers
Browse files Browse the repository at this point in the history
chore: replace hyperx with headers
  • Loading branch information
chriskrycho authored Jan 20, 2024
2 parents aace0e5 + 36f3529 commit 1776387
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 73 deletions.
139 changes: 100 additions & 39 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ winreg = "0.52.0"
hamcrest2 = "0.3.0"
envoy = "0.1.3"
ci_info = "0.14.14"
hyperx = "1.4.0"
headers = "0.3"

[workspace]
2 changes: 1 addition & 1 deletion crates/archive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ fs-utils = { path = "../fs-utils" }
progress-read = { path = "../progress-read" }
verbatim = "0.1"
cfg-if = "1.0"
hyperx = "1.0.0"
headers = "0.3"
thiserror = "1.0.16"
attohttpc = { version = "0.26", default-features = false, features = ["json", "compress", "tls-rustls-native-roots"] }
24 changes: 13 additions & 11 deletions crates/archive/src/tarball.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ use super::{Archive, ArchiveError, Origin};
use attohttpc::header::HeaderMap;
use flate2::read::GzDecoder;
use fs_utils::ensure_containing_dir_exists;
use hyperx::header::{
AcceptRanges, ByteRangeSpec, ContentLength, Header, Range, RangeUnit, TypedHeaders,
};
use headers::{AcceptRanges, ContentLength, Header, HeaderMapExt, Range};
use progress_read::ProgressRead;
use tee::TeeReader;

Expand All @@ -31,8 +29,7 @@ pub struct Tarball {
/// the HTTP `"Content-Length"` header.
fn content_length(headers: &HeaderMap) -> Result<u64, ArchiveError> {
headers
.decode::<ContentLength>()
.ok()
.typed_get::<ContentLength>()
.map(|v| v.0)
.ok_or_else(|| ArchiveError::MissingHeaderError(String::from("Content-Length")))
}
Expand Down Expand Up @@ -117,9 +114,16 @@ impl Archive for Tarball {
/// downloading the entire gzip file. For very small files it's unlikely to be
/// more efficient than simply downloading the entire file up front.
fn fetch_isize(url: &str, len: u64) -> Result<[u8; 4], ArchiveError> {
let range_header = Range::Bytes(vec![ByteRangeSpec::FromTo(len - 4, len - 1)]);
let mut header_values = Vec::with_capacity(1);
Range::bytes(len - 4..len)
.unwrap()
.encode(&mut header_values);
// We just pushed a header in with the `.encode` above, so there will always
// be a value at `.first()`.
let range_header = header_values.first().unwrap();

let (status, headers, mut response) = attohttpc::get(url)
.header(Range::header_name(), range_header.to_string())
.header(Range::name(), range_header)
.send()?
.split();

Expand Down Expand Up @@ -150,10 +154,8 @@ fn load_isize(file: &mut File) -> Result<[u8; 4], ArchiveError> {

fn accepts_byte_ranges(headers: &HeaderMap) -> bool {
headers
.decode::<AcceptRanges>()
.ok()
.map(|v| v.iter().any(|unit| *unit == RangeUnit::Bytes))
.unwrap_or(false)
.typed_get::<AcceptRanges>()
.map_or(false, |v| v == AcceptRanges::bytes())
}

/// Determines the uncompressed size of a gzip file hosted at the specified
Expand Down
2 changes: 1 addition & 1 deletion crates/volta-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ volta-layout = { path = "../volta-layout" }
once_cell = "1.19.0"
dunce = "1.0.4"
ci_info = "0.14.14"
hyperx = "1.4.0"
headers = "0.3"
attohttpc = { version = "0.26", default-features = false, features = ["json", "compress", "tls-rustls-native-roots"] }
chain-map = "0.1.0"
indexmap = "2.1.0"
Expand Down
Loading

0 comments on commit 1776387

Please sign in to comment.