From 48e53be24409357121a6c0c8f377bd2366340540 Mon Sep 17 00:00:00 2001 From: epi Date: Sun, 15 Nov 2020 06:37:39 -0600 Subject: [PATCH] cleaned up make_request, ran fmt --- src/lib.rs | 8 +++++++- src/logger.rs | 1 + src/reporter.rs | 2 +- src/scanner.rs | 5 +---- src/utils.rs | 28 +++++++++++++++++----------- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 518bf7e..a879c2f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -106,7 +106,13 @@ pub struct FeroxResponse { /// Implement Display for FeroxResponse impl fmt::Display for FeroxResponse { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "FeroxResponse {{ url: {}, status: {}, content-length: {} }}", self.url(), self.status(), self.content_length()) + write!( + f, + "FeroxResponse {{ url: {}, status: {}, content-length: {} }}", + self.url(), + self.status(), + self.content_length() + ) } } diff --git a/src/logger.rs b/src/logger.rs index c8fc902..3c681a3 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -61,6 +61,7 @@ pub fn initialize(verbosity: u8) { record.target(), style(record.args()).dim(), ); + PROGRESS_PRINTER.println(&msg); if let Some(buffered_file) = locked_file.clone() { diff --git a/src/reporter.rs b/src/reporter.rs index 8a295fb..f7db38f 100644 --- a/src/reporter.rs +++ b/src/reporter.rs @@ -1,5 +1,5 @@ use crate::config::{CONFIGURATION, PROGRESS_PRINTER}; -use crate::utils::{create_report_string, ferox_print, make_request, status_colorizer}; +use crate::utils::{create_report_string, ferox_print, make_request}; use crate::{FeroxChannel, FeroxResponse}; use console::strip_ansi_codes; use std::io::Write; diff --git a/src/scanner.rs b/src/scanner.rs index 9b73e22..96b4058 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -311,10 +311,7 @@ fn response_is_directory(response: &FeroxResponse) -> bool { } } None => { - log::debug!( - "expected Location header, but none was found: {}", - response - ); + log::debug!("expected Location header, but none was found: {}", response); log::trace!("exit: is_directory -> false"); return false; } diff --git a/src/utils.rs b/src/utils.rs index 399f844..f951992 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,8 +1,10 @@ -use crate::{config::{CONFIGURATION, PROGRESS_PRINTER}, FeroxError, FeroxResult}; +use crate::{ + config::{CONFIGURATION, PROGRESS_PRINTER}, + FeroxError, FeroxResult, +}; use console::{strip_ansi_codes, style, user_attended}; use indicatif::ProgressBar; -use reqwest::Url; -use reqwest::{Client, Response}; +use reqwest::{Url, Client, Response}; #[cfg(not(target_os = "windows"))] use rlimit::{getrlimit, setrlimit, Resource, Rlim}; use std::convert::TryInto; @@ -253,14 +255,18 @@ pub async fn make_request(client: &Client, url: &Url) -> FeroxResult { // only warn for timeouts, while actual errors are still left as errors log::warn!("Error while making request: {}", e); } else if e.is_redirect() { - let last_redirect = e.url().unwrap(); - let fancy_message = format!("{} !=> {}", url, last_redirect); - let report = create_report_string( - e.status().unwrap().as_str(), - "-1", - &fancy_message, - ); - ferox_print(&report, &PROGRESS_PRINTER) + 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() { + create_report_string(msg_status.as_str(), "-1", &fancy_message) + } else { + create_report_string("UNK", "-1", &fancy_message) + }; + + ferox_print(&report, &PROGRESS_PRINTER) + }; } else { log::error!("Error while making request: {}", e); }