@@ -9,9 +9,7 @@ use super::{Archive, ArchiveError, Origin};
99use attohttpc:: header:: HeaderMap ;
1010use flate2:: read:: GzDecoder ;
1111use 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 } ;
1513use progress_read:: ProgressRead ;
1614use tee:: TeeReader ;
1715
@@ -31,8 +29,7 @@ pub struct Tarball {
3129/// the HTTP `"Content-Length"` header.
3230fn 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.
119116fn 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
151155fn 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
0 commit comments