mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-22 14:08:23 -05:00
Compare commits
1 Commits
08079564eb
...
53ba78d0d6
Author | SHA1 | Date | |
---|---|---|---|
|
53ba78d0d6 |
@ -2,7 +2,6 @@
|
||||
//! search engines and then removes duplicate results.
|
||||
|
||||
use super::user_agent::random_user_agent;
|
||||
use crate::config::parser::Config;
|
||||
use crate::handler::{file_path, FileType};
|
||||
use crate::models::{
|
||||
aggregation_models::{EngineErrorInfo, SearchResult, SearchResults},
|
||||
@ -67,17 +66,20 @@ type FutureVec = Vec<JoinHandle<Result<HashMap<String, SearchResult>, Report<Eng
|
||||
pub async fn aggregate(
|
||||
query: &str,
|
||||
page: u32,
|
||||
config: &Config,
|
||||
random_delay: bool,
|
||||
debug: bool,
|
||||
upstream_search_engines: &[EngineHandler],
|
||||
request_timeout: u8,
|
||||
safe_search: u8,
|
||||
adaptive_window: bool,
|
||||
) -> Result<SearchResults, Box<dyn std::error::Error>> {
|
||||
let client = CLIENT.get_or_init(|| {
|
||||
ClientBuilder::new()
|
||||
.timeout(Duration::from_secs(config.request_timeout as u64)) // Add timeout to request to avoid DDOSing the server
|
||||
.timeout(Duration::from_secs(request_timeout as u64)) // Add timeout to request to avoid DDOSing the server
|
||||
.https_only(true)
|
||||
.gzip(true)
|
||||
.brotli(true)
|
||||
.http2_adaptive_window(config.adaptive_window)
|
||||
.http2_adaptive_window(adaptive_window)
|
||||
.build()
|
||||
.unwrap()
|
||||
});
|
||||
@ -85,7 +87,7 @@ pub async fn aggregate(
|
||||
let user_agent: &str = random_user_agent();
|
||||
|
||||
// Add a random delay before making the request.
|
||||
if config.aggregator.random_delay || !config.debug {
|
||||
if random_delay || !debug {
|
||||
let nanos = SystemTime::now().duration_since(UNIX_EPOCH)?.subsec_nanos() as f32;
|
||||
let delay = ((nanos / 1_0000_0000 as f32).floor() as u64) + 1;
|
||||
tokio::time::sleep(Duration::from_secs(delay)).await;
|
||||
|
@ -209,13 +209,16 @@ async fn results(
|
||||
aggregate(
|
||||
query,
|
||||
page,
|
||||
config,
|
||||
config.aggregator.random_delay,
|
||||
config.debug,
|
||||
&search_settings
|
||||
.engines
|
||||
.iter()
|
||||
.filter_map(|engine| EngineHandler::new(engine).ok())
|
||||
.collect::<Vec<EngineHandler>>(),
|
||||
config.request_timeout,
|
||||
safe_search_level,
|
||||
config.adaptive_window,
|
||||
)
|
||||
.await?
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user