mirror of
https://github.com/edu4rdshl/fhc.git
synced 2026-07-17 23:24:50 +00:00
Clippy fixes.
This commit is contained in:
parent
c6ea4c6ad8
commit
2fc3295827
2 changed files with 23 additions and 22 deletions
|
|
@ -1,5 +1,4 @@
|
||||||
use std::collections::{HashMap, HashSet};
|
use crate::structs::{HTTPFilters, LibOptions};
|
||||||
|
|
||||||
use async_recursion::async_recursion;
|
use async_recursion::async_recursion;
|
||||||
use rand::{distributions::Alphanumeric, thread_rng as rng, Rng};
|
use rand::{distributions::Alphanumeric, thread_rng as rng, Rng};
|
||||||
use reqwest::{
|
use reqwest::{
|
||||||
|
|
@ -7,9 +6,7 @@ use reqwest::{
|
||||||
redirect::Policy,
|
redirect::Policy,
|
||||||
Client, Response, Url,
|
Client, Response, Url,
|
||||||
};
|
};
|
||||||
|
use std::collections::{HashMap, HashSet};
|
||||||
use crate::structs::{HTTPFilters, LibOptions};
|
|
||||||
|
|
||||||
use {
|
use {
|
||||||
crate::{structs::HttpData, utils},
|
crate::{structs::HttpData, utils},
|
||||||
futures::stream::StreamExt,
|
futures::stream::StreamExt,
|
||||||
|
|
@ -19,6 +16,7 @@ use {
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
#[async_recursion]
|
#[async_recursion]
|
||||||
|
#[must_use]
|
||||||
pub async fn return_http_data(options: &LibOptions) -> HashMap<String, HttpData> {
|
pub async fn return_http_data(options: &LibOptions) -> HashMap<String, HttpData> {
|
||||||
let threads = if options.hosts.len() < options.threads {
|
let threads = if options.hosts.len() < options.threads {
|
||||||
options.hosts.len()
|
options.hosts.len()
|
||||||
|
|
@ -66,7 +64,7 @@ pub async fn return_http_data(options: &LibOptions) -> HashMap<String, HttpData>
|
||||||
response = Some(resp);
|
response = Some(resp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
counter += 1
|
counter += 1;
|
||||||
}
|
}
|
||||||
} else if let Ok(resp) = https_send_fut.send().await {
|
} else if let Ok(resp) = https_send_fut.send().await {
|
||||||
response = Some(resp);
|
response = Some(resp);
|
||||||
|
|
@ -76,7 +74,7 @@ pub async fn return_http_data(options: &LibOptions) -> HashMap<String, HttpData>
|
||||||
|
|
||||||
match response {
|
match response {
|
||||||
Some(resp) => {
|
Some(resp) => {
|
||||||
http_data.host_url = return_url(resp.url().to_owned()).await;
|
http_data.host_url = return_url(resp.url().clone());
|
||||||
if options.assign_response_data {
|
if options.assign_response_data {
|
||||||
http_data =
|
http_data =
|
||||||
assign_response_data(http_data, resp, options.return_filters).await;
|
assign_response_data(http_data, resp, options.return_filters).await;
|
||||||
|
|
@ -97,9 +95,9 @@ pub async fn return_http_data(options: &LibOptions) -> HashMap<String, HttpData>
|
||||||
&& http_data.status_code <= options.conditional_response_code + 99))
|
&& http_data.status_code <= options.conditional_response_code + 99))
|
||||||
{
|
{
|
||||||
if options.show_status_codes {
|
if options.show_status_codes {
|
||||||
println!("{},{}", http_data.host_url, http_data.status_code)
|
println!("{},{}", http_data.host_url, http_data.status_code);
|
||||||
} else {
|
} else {
|
||||||
println!("{}", http_data.host_url)
|
println!("{}", http_data.host_url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(host, http_data)
|
(host, http_data)
|
||||||
|
|
@ -110,6 +108,7 @@ pub async fn return_http_data(options: &LibOptions) -> HashMap<String, HttpData>
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn return_http_client(timeout: u64, max_redirects: usize) -> Client {
|
pub fn return_http_client(timeout: u64, max_redirects: usize) -> Client {
|
||||||
let policy = if max_redirects == 0 {
|
let policy = if max_redirects == 0 {
|
||||||
Policy::none()
|
Policy::none()
|
||||||
|
|
@ -127,7 +126,7 @@ pub fn return_http_client(timeout: u64, max_redirects: usize) -> Client {
|
||||||
.expect("Failed to create HTTP client")
|
.expect("Failed to create HTTP client")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn return_url(mut url: Url) -> String {
|
#[must_use] pub fn return_url(mut url: Url) -> String {
|
||||||
url.set_path("");
|
url.set_path("");
|
||||||
url.set_query(None);
|
url.set_query(None);
|
||||||
url.to_string()
|
url.to_string()
|
||||||
|
|
@ -140,7 +139,7 @@ pub async fn assign_response_data(
|
||||||
return_filers: bool,
|
return_filers: bool,
|
||||||
) -> HttpData {
|
) -> HttpData {
|
||||||
let headers = resp.headers().clone();
|
let headers = resp.headers().clone();
|
||||||
let url = resp.url().to_owned();
|
let url = resp.url().clone();
|
||||||
|
|
||||||
http_data.http_status = "ACTIVE".to_string();
|
http_data.http_status = "ACTIVE".to_string();
|
||||||
http_data.status_code = resp.status().as_u16();
|
http_data.status_code = resp.status().as_u16();
|
||||||
|
|
@ -170,7 +169,7 @@ pub async fn assign_response_data(
|
||||||
full_body.chars().count() as u64
|
full_body.chars().count() as u64
|
||||||
};
|
};
|
||||||
|
|
||||||
return_title_and_body(&mut http_data, &full_body).await;
|
return_title_and_body(&mut http_data, &full_body);
|
||||||
|
|
||||||
http_data.words_count = full_body.split(' ').count();
|
http_data.words_count = full_body.split(' ').count();
|
||||||
http_data.lines = full_body.lines().count() + 1;
|
http_data.lines = full_body.lines().count() + 1;
|
||||||
|
|
@ -185,16 +184,16 @@ pub async fn assign_response_data(
|
||||||
http_data
|
http_data
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn return_title_and_body(http_data: &mut HttpData, body: &str) {
|
pub fn return_title_and_body(http_data: &mut HttpData, body: &str) {
|
||||||
let document = Html::parse_document(body);
|
let document = Html::parse_document(body);
|
||||||
|
|
||||||
// Return title
|
// Return title
|
||||||
match Selector::parse("title") {
|
match Selector::parse("title") {
|
||||||
Ok(selector) => {
|
Ok(selector) => {
|
||||||
if let Some(title_element) = document.select(&selector).next() {
|
if let Some(title_element) = document.select(&selector).next() {
|
||||||
http_data.title = title_element.inner_html()
|
http_data.title = title_element.inner_html();
|
||||||
} else {
|
} else {
|
||||||
http_data.title = "NULL".to_string()
|
http_data.title = "NULL".to_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
@ -206,9 +205,9 @@ pub async fn return_title_and_body(http_data: &mut HttpData, body: &str) {
|
||||||
match Selector::parse("body") {
|
match Selector::parse("body") {
|
||||||
Ok(selector) => {
|
Ok(selector) => {
|
||||||
if let Some(body_element) = document.select(&selector).next() {
|
if let Some(body_element) = document.select(&selector).next() {
|
||||||
http_data.body = body_element.inner_html()
|
http_data.body = body_element.inner_html();
|
||||||
} else {
|
} else {
|
||||||
http_data.body = "NULL".to_string()
|
http_data.body = "NULL".to_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
|
||||||
12
src/utils.rs
12
src/utils.rs
|
|
@ -1,5 +1,6 @@
|
||||||
use rand::{seq::SliceRandom, thread_rng};
|
use rand::{seq::SliceRandom, thread_rng};
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn user_agents() -> Vec<String> {
|
pub fn user_agents() -> Vec<String> {
|
||||||
vec!["Mozilla/5.0 (Windows NT 6.1; WOW64; rv:77.0) Gecko/20190101 Firefox/77.0".to_string(),
|
vec!["Mozilla/5.0 (Windows NT 6.1; WOW64; rv:77.0) Gecko/20190101 Firefox/77.0".to_string(),
|
||||||
"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:77.0) Gecko/20100101 Firefox/77.0".to_string(),
|
"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:77.0) Gecko/20100101 Firefox/77.0".to_string(),
|
||||||
|
|
@ -32,10 +33,11 @@ pub fn user_agents() -> Vec<String> {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
pub fn return_random_string(strings: &[String]) -> String {
|
pub fn return_random_string(strings: &[String]) -> String {
|
||||||
if strings.is_empty() {
|
let empty_string = String::new();
|
||||||
String::new()
|
strings
|
||||||
} else {
|
.choose(&mut thread_rng())
|
||||||
strings.choose(&mut thread_rng()).unwrap().to_string()
|
.unwrap_or(&empty_string)
|
||||||
}
|
.to_string()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue