Trait fav_core::config::HttpConfig

source ·
pub trait HttpConfig {
    // Required methods
    fn headers(&self) -> HeaderMap;
    fn cookies(&self) -> &HashMap<String, String>;
    fn cookies_mut(&mut self) -> &mut HashMap<String, String>;

    // Provided methods
    fn extend_cookies(&mut self, cookies: HashMap<String, String>) { ... }
    fn cookie_value(
        &self,
        keys: impl IntoIterator<Item = impl AsRef<str>>
    ) -> HeaderValue { ... }
}
Expand description

A HttpConfig, including headers and cookies.

§Example


impl HttpConfig for Conf {
    fn headers(&self) -> HeaderMap {
        let mut hp = HeaderMap::new();
        hp.insert(header::USER_AGENT, "Mozilla/5.0".parse().unwrap());
        hp
    }

    fn cookies(&self) -> &HashMap<String, String> {
        &self.cookies
    }

    fn cookies_mut(&mut self) -> &mut HashMap<String, String> {
        &mut self.cookies
    }
}

Required Methods§

source

fn headers(&self) -> HeaderMap

The default headers

source

fn cookies(&self) -> &HashMap<String, String>

The cookies. HttpConfig::cookie_value uses this to generate the Cookie header.

§Caution

HttpConfig::cookie_value will omit the keys that are not in the cookies without any warning.

source

fn cookies_mut(&mut self) -> &mut HashMap<String, String>

The mutable reference to the cookies

Provided Methods§

source

fn extend_cookies(&mut self, cookies: HashMap<String, String>)

Set the cookies

source

fn cookie_value( &self, keys: impl IntoIterator<Item = impl AsRef<str>> ) -> HeaderValue

Acquire the cookie value by keys

Object Safety§

This trait is not object safe.

Implementors§