mirror of
https://github.com/edu4rdshl/fhc.git
synced 2026-07-17 23:24:50 +00:00
Fix issue causing a crash when cloning futures.
This commit is contained in:
parent
0a3288c435
commit
cd2dc1afc6
2 changed files with 37 additions and 43 deletions
|
|
@ -1,17 +1,19 @@
|
||||||
use crate::structs::{HTTPFilters, LibOptions};
|
|
||||||
use async_recursion::async_recursion;
|
|
||||||
use rand::{distributions::Alphanumeric, thread_rng as rng, Rng};
|
|
||||||
use reqwest::{
|
|
||||||
header::{CONTENT_LENGTH, CONTENT_TYPE},
|
|
||||||
redirect::Policy,
|
|
||||||
Client, Response, Url,
|
|
||||||
};
|
|
||||||
use std::collections::{HashMap, HashSet};
|
|
||||||
use {
|
use {
|
||||||
crate::{structs::HttpData, utils},
|
crate::{
|
||||||
|
structs::{HTTPFilters, HttpData, LibOptions},
|
||||||
|
utils,
|
||||||
|
},
|
||||||
|
async_recursion::async_recursion,
|
||||||
futures::stream::StreamExt,
|
futures::stream::StreamExt,
|
||||||
reqwest::{self, header::USER_AGENT},
|
rand::{distributions::Alphanumeric, thread_rng as rng, Rng},
|
||||||
|
reqwest::{
|
||||||
|
self,
|
||||||
|
header::{CONTENT_LENGTH, CONTENT_TYPE, USER_AGENT},
|
||||||
|
redirect::Policy,
|
||||||
|
Client, Response, Url,
|
||||||
|
},
|
||||||
scraper::{Html, Selector},
|
scraper::{Html, Selector},
|
||||||
|
std::collections::{HashMap, HashSet},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments)]
|
||||||
|
|
@ -31,12 +33,12 @@ pub async fn return_http_data(options: &LibOptions) -> HashMap<String, HttpData>
|
||||||
// Create futures
|
// Create futures
|
||||||
let https_send_fut = options
|
let https_send_fut = options
|
||||||
.client
|
.client
|
||||||
.get(&format!("https://{}", host))
|
.get(format!("https://{host}"))
|
||||||
.header(USER_AGENT, &user_agent);
|
.header(USER_AGENT, &user_agent);
|
||||||
|
|
||||||
let http_send_fut = options
|
let http_send_fut = options
|
||||||
.client
|
.client
|
||||||
.get(&format!("http://{}", host))
|
.get(format!("http://{host}"))
|
||||||
.header(USER_AGENT, &user_agent);
|
.header(USER_AGENT, &user_agent);
|
||||||
|
|
||||||
let mut http_data = HttpData::default();
|
let mut http_data = HttpData::default();
|
||||||
|
|
@ -47,24 +49,18 @@ pub async fn return_http_data(options: &LibOptions) -> HashMap<String, HttpData>
|
||||||
if options.retries != 1 {
|
if options.retries != 1 {
|
||||||
let mut counter = 0;
|
let mut counter = 0;
|
||||||
while counter < options.retries {
|
while counter < options.retries {
|
||||||
if let Ok(resp) = https_send_fut
|
if let Some(resp) = https_send_fut.try_clone() {
|
||||||
.try_clone()
|
if let Ok(resp) = resp.send().await {
|
||||||
.expect("Failed to clone https future")
|
response = Some(resp);
|
||||||
.send()
|
break;
|
||||||
.await
|
}
|
||||||
{
|
} else if let Some(resp) = http_send_fut.try_clone() {
|
||||||
response = Some(resp);
|
if let Ok(resp) = resp.send().await {
|
||||||
break;
|
response = Some(resp);
|
||||||
} else if let Ok(resp) = http_send_fut
|
break;
|
||||||
.try_clone()
|
}
|
||||||
.expect("Failed to clone http future")
|
counter += 1;
|
||||||
.send()
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
response = Some(resp);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
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);
|
||||||
|
|
@ -126,7 +122,8 @@ pub fn return_http_client(timeout: u64, max_redirects: usize) -> Client {
|
||||||
.expect("Failed to create HTTP client")
|
.expect("Failed to create HTTP client")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use] pub 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()
|
||||||
|
|
@ -152,10 +149,10 @@ pub async fn assign_response_data(
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.to_string()
|
.to_string()
|
||||||
} else {
|
} else {
|
||||||
"".to_string()
|
String::new()
|
||||||
};
|
};
|
||||||
|
|
||||||
http_data.headers = format!("{:?}", headers);
|
http_data.headers = format!("{headers:?}");
|
||||||
|
|
||||||
let full_body = resp.text().await.unwrap_or_default();
|
let full_body = resp.text().await.unwrap_or_default();
|
||||||
|
|
||||||
|
|
@ -197,7 +194,7 @@ pub fn return_title_and_body(http_data: &mut HttpData, body: &str) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Failed to parse selector: {:?}", err);
|
eprintln!("Failed to parse selector: {err:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -211,7 +208,7 @@ pub fn return_title_and_body(http_data: &mut HttpData, body: &str) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Failed to parse selector: {:?}", err);
|
eprintln!("Failed to parse selector: {err:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -255,8 +252,8 @@ pub async fn return_filters_data(
|
||||||
|
|
||||||
let data = return_http_data(&lib_options).await;
|
let data = return_http_data(&lib_options).await;
|
||||||
|
|
||||||
data.iter()
|
data.values()
|
||||||
.map(|(_, http_data)| {
|
.map(|http_data| {
|
||||||
http_filters
|
http_filters
|
||||||
.bad_http_lengths
|
.bad_http_lengths
|
||||||
.append(&mut vec![http_data.content_length.to_string()]);
|
.append(&mut vec![http_data.content_length.to_string()]);
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,7 @@
|
||||||
use std::collections::HashSet;
|
|
||||||
|
|
||||||
use fhc::{httplib, structs::LibOptions};
|
|
||||||
|
|
||||||
use {
|
use {
|
||||||
clap::{value_t, App, Arg},
|
clap::{value_t, App, Arg},
|
||||||
fhc::utils,
|
fhc::{httplib, structs::LibOptions, utils},
|
||||||
|
std::collections::HashSet,
|
||||||
tokio::{
|
tokio::{
|
||||||
self,
|
self,
|
||||||
io::{self, AsyncReadExt},
|
io::{self, AsyncReadExt},
|
||||||
|
|
@ -128,7 +125,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let domain = value_t!(matches, "domain", String).unwrap();
|
let domain = value_t!(matches, "domain", String).unwrap();
|
||||||
buffer
|
buffer
|
||||||
.lines()
|
.lines()
|
||||||
.map(|word| format!("{}.{}", word, domain))
|
.map(|word| format!("{word}.{domain}"))
|
||||||
.collect()
|
.collect()
|
||||||
} else {
|
} else {
|
||||||
buffer.lines().map(str::to_owned).collect()
|
buffer.lines().map(str::to_owned).collect()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue