Skip to content

Commit 1776387

Browse files
authored
Merge pull request #1659 from tottoto/replace-hyperx-with-headers
chore: replace hyperx with headers
2 parents aace0e5 + 36f3529 commit 1776387

File tree

7 files changed

+151
-73
lines changed

7 files changed

+151
-73
lines changed

Cargo.lock

Lines changed: 100 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ winreg = "0.52.0"
4444
hamcrest2 = "0.3.0"
4545
envoy = "0.1.3"
4646
ci_info = "0.14.14"
47-
hyperx = "1.4.0"
47+
headers = "0.3"
4848

4949
[workspace]

crates/archive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ fs-utils = { path = "../fs-utils" }
1616
progress-read = { path = "../progress-read" }
1717
verbatim = "0.1"
1818
cfg-if = "1.0"
19-
hyperx = "1.0.0"
19+
headers = "0.3"
2020
thiserror = "1.0.16"
2121
attohttpc = { version = "0.26", default-features = false, features = ["json", "compress", "tls-rustls-native-roots"] }

crates/archive/src/tarball.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ use super::{Archive, ArchiveError, Origin};
99
use attohttpc::header::HeaderMap;
1010
use flate2::read::GzDecoder;
1111
use fs_utils::ensure_containing_dir_exists;
12-
use hyperx::header::{
13-
AcceptRanges, ByteRangeSpec, ContentLength, Header, Range, RangeUnit, TypedHeaders,
14-
};
12+
use headers::{AcceptRanges, ContentLength, Header, HeaderMapExt, Range};
1513
use progress_read::ProgressRead;
1614
use tee::TeeReader;
1715

@@ -31,8 +29,7 @@ pub struct Tarball {
3129
/// the HTTP `"Content-Length"` header.
3230
fn content_length(headers: &HeaderMap) -> Result<u64, ArchiveError> {
3331
headers
34-
.decode::<ContentLength>()
35-
.ok()
32+
.typed_get::<ContentLength>()
3633
.map(|v| v.0)
3734
.ok_or_else(|| ArchiveError::MissingHeaderError(String::from("Content-Length")))
3835
}
@@ -117,9 +114,16 @@ impl Archive for Tarball {
117114
/// downloading the entire gzip file. For very small files it's unlikely to be
118115
/// more efficient than simply downloading the entire file up front.
119116
fn fetch_isize(url: &str, len: u64) -> Result<[u8; 4], ArchiveError> {
120-
let range_header = Range::Bytes(vec![ByteRangeSpec::FromTo(len - 4, len - 1)]);
117+
let mut header_values = Vec::with_capacity(1);
118+
Range::bytes(len - 4..len)
119+
.unwrap()
120+
.encode(&mut header_values);
121+
// We just pushed a header in with the `.encode` above, so there will always
122+
// be a value at `.first()`.
123+
let range_header = header_values.first().unwrap();
124+
121125
let (status, headers, mut response) = attohttpc::get(url)
122-
.header(Range::header_name(), range_header.to_string())
126+
.header(Range::name(), range_header)
123127
.send()?
124128
.split();
125129

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

151155
fn accepts_byte_ranges(headers: &HeaderMap) -> bool {
152156
headers
153-
.decode::<AcceptRanges>()
154-
.ok()
155-
.map(|v| v.iter().any(|unit| *unit == RangeUnit::Bytes))
156-
.unwrap_or(false)
157+
.typed_get::<AcceptRanges>()
158+
.map_or(false, |v| v == AcceptRanges::bytes())
157159
}
158160

159161
/// Determines the uncompressed size of a gzip file hosted at the specified

crates/volta-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ volta-layout = { path = "../volta-layout" }
4747
once_cell = "1.19.0"
4848
dunce = "1.0.4"
4949
ci_info = "0.14.14"
50-
hyperx = "1.4.0"
50+
headers = "0.3"
5151
attohttpc = { version = "0.26", default-features = false, features = ["json", "compress", "tls-rustls-native-roots"] }
5252
chain-map = "0.1.0"
5353
indexmap = "2.1.0"

0 commit comments

Comments
 (0)