mirror of
https://github.com/edu4rdshl/fhc.git
synced 2026-07-17 23:24:50 +00:00
Performance improvements.
Signed-off-by: Eduard Tolosa <edu4rdshl@protonmail.com>
This commit is contained in:
parent
c5c4b28b2c
commit
5e557a3306
1 changed files with 17 additions and 20 deletions
|
|
@ -80,11 +80,11 @@ pub async fn return_http_data(options: &LibOptions) -> HashMap<String, HttpData>
|
||||||
|
|
||||||
match response {
|
match response {
|
||||||
Some(resp) => {
|
Some(resp) => {
|
||||||
|
http_data.host_url = if is_http { http_url } else { https_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;
|
||||||
} else {
|
} else {
|
||||||
http_data.host_url = if is_http { http_url } else { https_url.clone() };
|
|
||||||
http_data.status_code = resp.status().as_u16();
|
http_data.status_code = resp.status().as_u16();
|
||||||
http_data.http_status = "ACTIVE".to_string();
|
http_data.http_status = "ACTIVE".to_string();
|
||||||
};
|
};
|
||||||
|
|
@ -132,15 +132,11 @@ 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 mut url = resp.url().to_owned();
|
let url = resp.url().to_owned();
|
||||||
|
|
||||||
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();
|
||||||
http_data.host_url = {
|
|
||||||
url.set_path("");
|
|
||||||
url.set_query(None);
|
|
||||||
url.to_string()
|
|
||||||
};
|
|
||||||
http_data.final_url = url.to_string();
|
http_data.final_url = url.to_string();
|
||||||
http_data.protocol = resp.url().scheme().to_string();
|
http_data.protocol = resp.url().scheme().to_string();
|
||||||
http_data.content_type = if headers.contains_key(CONTENT_TYPE) {
|
http_data.content_type = if headers.contains_key(CONTENT_TYPE) {
|
||||||
|
|
@ -166,8 +162,8 @@ pub async fn assign_response_data(
|
||||||
full_body.chars().count() as u64
|
full_body.chars().count() as u64
|
||||||
};
|
};
|
||||||
|
|
||||||
http_data.body = return_body(&full_body).await;
|
return_title_and_body(&mut http_data, &full_body).await;
|
||||||
http_data.title = return_title(&full_body).await;
|
|
||||||
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;
|
||||||
|
|
||||||
|
|
@ -181,38 +177,38 @@ pub async fn assign_response_data(
|
||||||
http_data
|
http_data
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn return_title(data: &str) -> String {
|
pub async fn return_title_and_body(http_data: &mut HttpData, body: &str) {
|
||||||
let document = Html::parse_document(data);
|
let document = Html::parse_document(body);
|
||||||
|
|
||||||
|
// 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() {
|
||||||
title_element.inner_html()
|
http_data.title = title_element.inner_html()
|
||||||
} else {
|
} else {
|
||||||
"NULL".to_string()
|
http_data.title = "NULL".to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Failed to parse selector: {:?}", err);
|
eprintln!("Failed to parse selector: {:?}", err);
|
||||||
String::new()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn return_body(data: &str) -> String {
|
// Return body
|
||||||
let document = Html::parse_document(data);
|
|
||||||
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() {
|
||||||
body_element.inner_html()
|
http_data.body = body_element.inner_html()
|
||||||
} else {
|
} else {
|
||||||
"NULL".to_string()
|
http_data.body = "NULL".to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Failed to parse selector: {:?}", err);
|
eprintln!("Failed to parse selector: {:?}", err);
|
||||||
String::new()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drop(document);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn return_filters_data(
|
pub async fn return_filters_data(
|
||||||
|
|
@ -245,6 +241,7 @@ pub async fn return_filters_data(
|
||||||
user_agents: user_agents_list,
|
user_agents: user_agents_list,
|
||||||
retries: 1,
|
retries: 1,
|
||||||
threads,
|
threads,
|
||||||
|
assign_response_data: true,
|
||||||
quiet_flag: true,
|
quiet_flag: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue