mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-24 06:58:22 -05:00
Compare commits
1 Commits
3989c88ff1
...
37f47ea63f
Author | SHA1 | Date | |
---|---|---|---|
|
37f47ea63f |
@ -17,8 +17,7 @@ reqwest = { version = "0.12.5", default-features = false, features = [
|
|||||||
"rustls-tls",
|
"rustls-tls",
|
||||||
"brotli",
|
"brotli",
|
||||||
"gzip",
|
"gzip",
|
||||||
"http2",
|
"http2"
|
||||||
"socks",
|
|
||||||
] }
|
] }
|
||||||
tokio = { version = "1.32.0", features = [
|
tokio = { version = "1.32.0", features = [
|
||||||
"rt-multi-thread",
|
"rt-multi-thread",
|
||||||
|
@ -6,7 +6,6 @@ use crate::handler::{file_path, FileType};
|
|||||||
use crate::models::parser_models::{AggregatorConfig, RateLimiter, Style};
|
use crate::models::parser_models::{AggregatorConfig, RateLimiter, Style};
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
use mlua::Lua;
|
use mlua::Lua;
|
||||||
use reqwest::Proxy;
|
|
||||||
use std::{collections::HashMap, fs, thread::available_parallelism};
|
use std::{collections::HashMap, fs, thread::available_parallelism};
|
||||||
|
|
||||||
/// A named struct which stores the parsed config file options.
|
/// A named struct which stores the parsed config file options.
|
||||||
@ -49,8 +48,6 @@ pub struct Config {
|
|||||||
pub tcp_connection_keep_alive: u8,
|
pub tcp_connection_keep_alive: u8,
|
||||||
/// It stores the pool idle connection timeout in seconds.
|
/// It stores the pool idle connection timeout in seconds.
|
||||||
pub pool_idle_connection_timeout: u8,
|
pub pool_idle_connection_timeout: u8,
|
||||||
/// Url of the proxy to use for outgoing requests.
|
|
||||||
pub proxy: Option<Proxy>,
|
|
||||||
/// It stores the number of https connections to keep in the pool.
|
/// It stores the number of https connections to keep in the pool.
|
||||||
pub number_of_https_connections: u8,
|
pub number_of_https_connections: u8,
|
||||||
}
|
}
|
||||||
@ -123,14 +120,6 @@ impl Config {
|
|||||||
_ => parsed_cet,
|
_ => parsed_cet,
|
||||||
};
|
};
|
||||||
|
|
||||||
let proxy_opt = globals.get::<_, Option<String>>("proxy")?;
|
|
||||||
let proxy = proxy_opt.and_then(|proxy_str| {
|
|
||||||
Proxy::all(proxy_str).ok().and_then(|_| {
|
|
||||||
log::error!("Invalid proxy url, defaulting to no proxy.");
|
|
||||||
None
|
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok(Config {
|
Ok(Config {
|
||||||
port: globals.get::<_, u16>("port")?,
|
port: globals.get::<_, u16>("port")?,
|
||||||
binding_ip: globals.get::<_, String>("binding_ip")?,
|
binding_ip: globals.get::<_, String>("binding_ip")?,
|
||||||
@ -162,7 +151,6 @@ impl Config {
|
|||||||
safe_search,
|
safe_search,
|
||||||
#[cfg(any(feature = "redis-cache", feature = "memory-cache"))]
|
#[cfg(any(feature = "redis-cache", feature = "memory-cache"))]
|
||||||
cache_expiry_time,
|
cache_expiry_time,
|
||||||
proxy,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ pub async fn aggregate(
|
|||||||
safe_search: u8,
|
safe_search: u8,
|
||||||
) -> Result<SearchResults, Box<dyn std::error::Error>> {
|
) -> Result<SearchResults, Box<dyn std::error::Error>> {
|
||||||
let client = CLIENT.get_or_init(|| {
|
let client = CLIENT.get_or_init(|| {
|
||||||
let mut cb = ClientBuilder::new()
|
ClientBuilder::new()
|
||||||
.timeout(Duration::from_secs(config.request_timeout as u64)) // Add timeout to request to avoid DDOSing the server
|
.timeout(Duration::from_secs(config.request_timeout as u64)) // Add timeout to request to avoid DDOSing the server
|
||||||
.pool_idle_timeout(Duration::from_secs(
|
.pool_idle_timeout(Duration::from_secs(
|
||||||
config.pool_idle_connection_timeout as u64,
|
config.pool_idle_connection_timeout as u64,
|
||||||
@ -86,13 +86,9 @@ pub async fn aggregate(
|
|||||||
.https_only(true)
|
.https_only(true)
|
||||||
.gzip(true)
|
.gzip(true)
|
||||||
.brotli(true)
|
.brotli(true)
|
||||||
.http2_adaptive_window(config.adaptive_window);
|
.http2_adaptive_window(config.adaptive_window)
|
||||||
|
.build()
|
||||||
if config.proxy.is_some() {
|
.unwrap()
|
||||||
cb = cb.proxy(config.proxy.clone().unwrap());
|
|
||||||
}
|
|
||||||
|
|
||||||
cb.build().unwrap()
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let user_agent: &str = random_user_agent();
|
let user_agent: &str = random_user_agent();
|
||||||
@ -246,7 +242,6 @@ pub async fn filter_with_lists(
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sorts SearchResults by relevance score.
|
/// Sorts SearchResults by relevance score.
|
||||||
/// <br> sort_unstable is used as its faster,stability is not an issue on our side.
|
/// <br> sort_unstable is used as its faster,stability is not an issue on our side.
|
||||||
/// For reasons why, check out [`this`](https://rust-lang.github.io/rfcs/1884-unstable-sort.html)
|
/// For reasons why, check out [`this`](https://rust-lang.github.io/rfcs/1884-unstable-sort.html)
|
||||||
@ -262,7 +257,6 @@ fn sort_search_results(results: &mut [SearchResult]) {
|
|||||||
.unwrap_or(Ordering::Less)
|
.unwrap_or(Ordering::Less)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -75,5 +75,3 @@ upstream_search_engines = {
|
|||||||
Mojeek = false,
|
Mojeek = false,
|
||||||
Bing = false,
|
Bing = false,
|
||||||
} -- select the upstream search engines from which the results should be fetched.
|
} -- select the upstream search engines from which the results should be fetched.
|
||||||
|
|
||||||
proxy = nil -- Proxy to send outgoing requests through. Set to nil to disable.
|
|
Loading…
Reference in New Issue
Block a user