mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-21 21:48:21 -05:00
✨ feat(config): config option to keep tcp
connection alive for a certain period for subsequent requests (#548)
* Added new HTTP connection setting to the reqwest::ClientBuilder to timeout requests for fetching the search results from the upstream search engines. * Provided a config option under the server section of the config to allow users to keep tcp connections alive for each request for a certain period of time * Update src/results/aggregator.rs Co-authored-by: neon_arch <mustafadhuleb53@gmail.com> * Update src/results/aggregator.rs Co-authored-by: neon_arch <mustafadhuleb53@gmail.com> * Fixed import issue in `tcp_connection_keepalive` * updated size to u8 Co-authored-by: neon_arch <mustafadhuleb53@gmail.com> * Fixed sizer eror in `parser.rs` --------- Co-authored-by: neon_arch <mustafadhuleb53@gmail.com> Co-authored-by: alamin655 <129589283+alamin655@users.noreply.github.com>
This commit is contained in:
parent
ce4912b9c5
commit
c584a7d601
@ -42,6 +42,8 @@ pub struct Config {
|
|||||||
/// It stores the level of safe search to be used for restricting content in the
|
/// It stores the level of safe search to be used for restricting content in the
|
||||||
/// search results.
|
/// search results.
|
||||||
pub safe_search: u8,
|
pub safe_search: u8,
|
||||||
|
/// It stores the TCP connection keepalive duration in seconds.
|
||||||
|
pub tcp_connection_keepalive: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
@ -131,6 +133,7 @@ impl Config {
|
|||||||
upstream_search_engines: globals
|
upstream_search_engines: globals
|
||||||
.get::<_, HashMap<String, bool>>("upstream_search_engines")?,
|
.get::<_, HashMap<String, bool>>("upstream_search_engines")?,
|
||||||
request_timeout: globals.get::<_, u8>("request_timeout")?,
|
request_timeout: globals.get::<_, u8>("request_timeout")?,
|
||||||
|
tcp_connection_keepalive: globals.get::<_, u8>("tcp_connection_keepalive")?,
|
||||||
threads,
|
threads,
|
||||||
rate_limiter: RateLimiter {
|
rate_limiter: RateLimiter {
|
||||||
number_of_requests: rate_limiter["number_of_requests"],
|
number_of_requests: rate_limiter["number_of_requests"],
|
||||||
|
@ -77,6 +77,7 @@ pub async fn aggregate(
|
|||||||
let client = CLIENT.get_or_init(|| {
|
let client = CLIENT.get_or_init(|| {
|
||||||
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
|
||||||
|
.tcp_keepalive(Duration::from_secs(config.tcp_connection_keepalive as u64))
|
||||||
.connect_timeout(Duration::from_secs(config.request_timeout as u64)) // Add timeout to request to avoid DDOSing the server
|
.connect_timeout(Duration::from_secs(config.request_timeout as u64)) // Add timeout to request to avoid DDOSing the server
|
||||||
.https_only(true)
|
.https_only(true)
|
||||||
.gzip(true)
|
.gzip(true)
|
||||||
|
@ -10,6 +10,7 @@ production_use = false -- whether to use production mode or not (in other words
|
|||||||
-- if production_use is set to true
|
-- if production_use is set to true
|
||||||
-- There will be a random delay before sending the request to the search engines, this is to prevent DDoSing the upstream search engines from a large number of simultaneous requests.
|
-- There will be a random delay before sending the request to the search engines, this is to prevent DDoSing the upstream search engines from a large number of simultaneous requests.
|
||||||
request_timeout = 30 -- timeout for the search requests sent to the upstream search engines to be fetched (value in seconds).
|
request_timeout = 30 -- timeout for the search requests sent to the upstream search engines to be fetched (value in seconds).
|
||||||
|
tcp_connection_keepalive = 30 -- the amount of time the tcp connection should remain alive (or connected to the server). (value in seconds).
|
||||||
rate_limiter = {
|
rate_limiter = {
|
||||||
number_of_requests = 20, -- The number of request that are allowed within a provided time limit.
|
number_of_requests = 20, -- The number of request that are allowed within a provided time limit.
|
||||||
time_limit = 3, -- The time limit in which the quantity of requests that should be accepted.
|
time_limit = 3, -- The time limit in which the quantity of requests that should be accepted.
|
||||||
|
Loading…
Reference in New Issue
Block a user