Skip to main content

HeaderUtils

Trait HeaderUtils 

Source
pub trait HeaderUtils {
    // Required methods
    fn extract_filename(&self) -> Result<String, Box<dyn Error + Send + Sync>>;
    fn extract_file_size(&self) -> Result<u64, Box<dyn Error + Send + Sync>>;
}

Required Methods§

Source

fn extract_filename(&self) -> Result<String, Box<dyn Error + Send + Sync>>

§extract_filename

When response header provides content disposition or any other keys to provide file name or file type, we can extract it from here.

We can also guess file name from the url and content-type too.

Source

fn extract_file_size(&self) -> Result<u64, Box<dyn Error + Send + Sync>>

§extract_file_size

When response header provides content-range, it is easy to extract the actual file size in bytes.

example response: Content-Range bytes 0-0/360996864

From the above response header, we can extract value in bytes

It will help us downloading partial data with multiple threads.

Implementations on Foreign Types§

Source§

impl HeaderUtils for HeaderMap

Since HeaderMap is imported from Reqwest, we need to define trait and then implement it to the HeaderMap struct.

Source§

fn extract_file_size(&self) -> Result<u64, Box<dyn Error + Send + Sync>>

Returns the file size in bytes.

If the content-length is is not found or not extracted, it just returns Error

Source§

fn extract_filename(&self) -> Result<String, Box<dyn Error + Send + Sync>>

Implementors§