pub async fn make_request(
    client: &Client,
    url: &Url,
    output_level: OutputLevel,
    config: &Configuration,
    tx_stats: UnboundedSender<Command>,
) -> Result<Response> {
    log::trace!(
        "enter: make_request(Configuration::Client, {}, {:?}, {:?})",
        url,
        output_level,
        tx_stats
    );

    let mut request = client.get(url.to_owned());

    if config.random_agent {
        let index = unsafe {
            USER_AGENT_CTR += 1;
            USER_AGENT_CTR % USER_AGENTS.len()
        };

        let user_agent = USER_AGENTS[index];

        request = request.header("User-Agent", user_agent);
    }

    match request.send().await {
        Err(e) => {
            log::trace!("exit: make_request -> {}", e);

            if e.is_timeout() {
                send_command!(tx_stats, AddError(Timeout));
            } else if e.is_redirect() {
                if let Some(last_redirect) = e.url() {
                    // get where we were headed (last_redirect) and where we came from (url)
                    let fancy_message = format!("{} !=> {}", url, last_redirect);

                    let report = if let Some(msg_status) = e.status() {
                        send_command!(tx_stats, AddStatus(msg_status));
                        create_report_string(
                            msg_status.as_str(),
                            "-1",
                            "-1",
                            "-1",
                            &fancy_message,
                            output_level,
                        )
                    } else {
                        create_report_string("UNK", "-1", "-1", "-1", &fancy_message, output_level)
                    };

                    send_command!(tx_stats, AddError(Redirection));

                    ferox_print(&report, &PROGRESS_PRINTER)
                };
            } else if e.is_connect() {
                send_command!(tx_stats, AddError(Connection));
            } else if e.is_request() {
                send_command!(tx_stats, AddError(Request));
            } else {
                send_command!(tx_stats, AddError(Other));
            }

            log::warn!("Error while making request: {}", e);
            bail!("{}", e)
        }
        Ok(resp) => {
            log::trace!("exit: make_request -> {:?}", resp);
            send_command!(tx_stats, AddStatus(resp.status()));
            Ok(resp)
        }
    }
}
/// Initiate request to the given `Url` using `Client`
Initiate request to the given `Url` using `Client`
Initiate request to the given ` Url ` using ` Client `
pub async fn make_request(
    client: &Client,
    url: &Url,
    output_level: OutputLevel,
    config: &Configuration,
    tx_stats: UnboundedSender<Command>,
) -> Result<Response> {
    log::trace!(
        "enter: make_request(Configuration::Client, {}, {:?}, {:?})",
        url,
        output_level,
        tx_stats
    );
    let mut request = client.get(url.to_owned());
    if config.random_agent {
        let index = unsafe {
            USER_AGENT_CTR += 1;
            USER_AGENT_CTR % USER_AGENTS.len()
        };
        let user_agent = USER_AGENTS[index];
        request = request.header("User-Agent", user_agent);
    }
    match request.send().await {
        Err(e) => {
            log::trace!("exit: make_request -> {}", e);
            if e.is_timeout() {
                send_command!(tx_stats, AddError(Timeout));
            } else if e.is_redirect() {
                if let Some(last_redirect) = e.url() {
                    // get where we were headed (last_redirect) and where we came from (url)
                    let fancy_message = format!("{} !=> {}", url, last_redirect);
                    let report = if let Some(msg_status) = e.status() {
                        send_command!(tx_stats, AddStatus(msg_status));
                        create_report_string(
                            msg_status.as_str(),
                            "-1",
                            "-1",
                            "-1",
                            &fancy_message,
                            output_level,
                        )
                    } else {
                        create_report_string("UNK", "-1", "-1", "-1", &fancy_message, output_level)
                    };
                    send_command!(tx_stats, AddError(Redirection));
                    ferox_print(&report, &PROGRESS_PRINTER)
                };
            } else if e.is_connect() {
                send_command!(tx_stats, AddError(Connection));
            } else if e.is_request() {
                send_command!(tx_stats, AddError(Request));
            } else {
                send_command!(tx_stats, AddError(Other));
            }
            log::warn!("Error while making request: {}", e);
            bail!("{}", e)
        }
        Ok(resp) => {
            log::trace!("exit: make_request -> {:?}", resp);
            send_command!(tx_stats, AddStatus(resp.status()));
            Ok(resp)
        }
    }
}
pub async fn make_request ( client : & Client , url : & Url , output_level : OutputLevel , config : & Configuration , tx_stats : UnboundedSender < Command > , ) -> Result < Response > { log :: trace ! ( " " url output_level tx_stats ) ; let mut request = client . get ( url . to_owned ( ) ) ; if config . random_agent { let index = unsafe { USER_AGENT_CTR += 1 ; USER_AGENT_CTR % USER_AGENTS . len ( ) } ; let user_agent = USER_AGENTS [ index ] ; request = request . header ( " " , user_agent ) ; } match request . send ( ) . await { Err ( e ) => { log :: trace ! ( " " e ) ; if e . is_timeout ( ) { send_command ! ( tx_stats AddError ( Timeout ) ) ; } else if e . is_redirect ( ) { if let Some ( last_redirect ) = e . url ( ) { // get where we were headed (last_redirect) and where we came from (url) let fancy_message = format ! ( " " url last_redirect ) ; let report = if let Some ( msg_status ) = e . status ( ) { send_command ! ( tx_stats AddStatus ( msg_status ) ) ; create_report_string ( msg_status . as_str ( ) , " " , " " , " " , & fancy_message , output_level , ) } else { create_report_string ( " " , " " , " " , " " , & fancy_message , output_level ) } ; send_command ! ( tx_stats AddError ( Redirection ) ) ; ferox_print ( & report , & PROGRESS_PRINTER ) } ; } else if e . is_connect ( ) { send_command ! ( tx_stats AddError ( Connection ) ) ; } else if e . is_request ( ) { send_command ! ( tx_stats AddError ( Request ) ) ; } else { send_command ! ( tx_stats AddError ( Other ) ) ; } log :: warn ! ( " " e ) ; bail ! ( " " e ) } Ok ( resp ) => { log :: trace ! ( " " resp ) ; send_command ! ( tx_stats AddStatus ( resp status ( ) ) ) ; Ok ( resp ) } } }
Initiate request to the given `Url` using `Client`
Initiate request to the given ` Url ` using ` Client `
client
&Client
url
&Url
output_level
OutputLevel
config
&Configuration
tx_stats
UnboundedSender<Command>