pub async fn create_client(
    user_agent: Option<String>,
    proxies: Option<Vec<Proxy>>,
    connect_timeout: Option<Duration>,
) -> Result<Client, Error> {
    let mut builder = reqwest::Client::builder()
        .cookie_store(true)
        .redirect(Policy::none());
    if let Some(ua) = user_agent {
        builder = builder.user_agent(ua);
    }
    if let Some(mut proxy) = proxies {
        while !proxy.is_empty() {
            builder = builder.proxy(proxy.pop().unwrap())
        }
    }
    if let Some(timeout) = connect_timeout {
        builder = builder.connect_timeout(timeout);
    }

    let params = [("yes", "yes")];
    let url = format!("{}/ask/over18", PTT_CC_URL);
    let client = builder.build()?;
    match client.post(&url).form(&params).send().await {
        Ok(_) => Ok(client),
        Err(e) => Err(Error::ConnectionError(e)),
    }
}
/// Return a HTTP Client with cookie accepting over 18 agreement.
/// One should reuse returned client as more as possible.
Return a HTTP Client with cookie accepting over 18 agreement.
One should reuse returned client as more as possible.
Return a HTTP Client with cookie accepting over 18 agreement . One should reuse returned client as more as possible .
pub async fn create_client(
    user_agent: Option<String>,
    proxies: Option<Vec<Proxy>>,
    connect_timeout: Option<Duration>,
) -> Result<Client, Error> {
    let mut builder = reqwest::Client::builder()
        .cookie_store(true)
        .redirect(Policy::none());
    if let Some(ua) = user_agent {
        builder = builder.user_agent(ua);
    }
    if let Some(mut proxy) = proxies {
        while !proxy.is_empty() {
            builder = builder.proxy(proxy.pop().unwrap())
        }
    }
    if let Some(timeout) = connect_timeout {
        builder = builder.connect_timeout(timeout);
    }
    let params = [("yes", "yes")];
    let url = format!("{}/ask/over18", PTT_CC_URL);
    let client = builder.build()?;
    match client.post(&url).form(&params).send().await {
        Ok(_) => Ok(client),
        Err(e) => Err(Error::ConnectionError(e)),
    }
}
pub async fn create_client ( user_agent : Option < String > , proxies : Option < Vec < Proxy > > , connect_timeout : Option < Duration > , ) -> Result < Client , Error > { let mut builder = reqwest :: Client :: builder ( ) . cookie_store ( true ) . redirect ( Policy :: none ( ) ) ; if let Some ( ua ) = user_agent { builder = builder . user_agent ( ua ) ; } if let Some ( mut proxy ) = proxies { while ! proxy . is_empty ( ) { builder = builder . proxy ( proxy . pop ( ) . unwrap ( ) ) } } if let Some ( timeout ) = connect_timeout { builder = builder . connect_timeout ( timeout ) ; } let params = [ ( " " , " " ) ] ; let url = format ! ( " " PTT_CC_URL ) ; let client = builder . build ( ) ? ; match client . post ( & url ) . form ( & params ) . send ( ) . await { Ok ( _ ) => Ok ( client ) , Err ( e ) => Err ( Error :: ConnectionError ( e ) ) , } }
Return a HTTP Client with cookie accepting over 18 agreement.
Return a HTTP Client with cookie accepting over 18 agreement .
user_agent
Option<String>
proxies
Option<Vec<Proxy>>
connect_timeout
Option<Duration>