0
0
mirror of https://github.com/neon-mmd/websurfx.git synced 2024-11-22 05:58:21 -05:00

chore: add enum to handle different reqwest errors & add timeout to requests

This commit is contained in:
neon_arch 2023-05-16 12:22:00 +03:00
parent 318be6ef7e
commit 019b3322e7
3 changed files with 11 additions and 1 deletions

View File

@ -2,7 +2,7 @@
//! by querying the upstream duckduckgo search engine with user provided query and with a page //! by querying the upstream duckduckgo search engine with user provided query and with a page
//! number if provided. //! number if provided.
use std::collections::HashMap; use std::{collections::HashMap, time::Duration};
use reqwest::header::{HeaderMap, CONTENT_TYPE, COOKIE, REFERER, USER_AGENT}; use reqwest::header::{HeaderMap, CONTENT_TYPE, COOKIE, REFERER, USER_AGENT};
use scraper::{Html, Selector}; use scraper::{Html, Selector};
@ -57,6 +57,7 @@ pub async fn results(
// TODO: Write better error handling code to handle no results case. // TODO: Write better error handling code to handle no results case.
let results: String = reqwest::Client::new() let results: String = reqwest::Client::new()
.get(url) .get(url)
.timeout(Duration::from_secs(30))
.headers(header_map) // add spoofed headers to emulate human behaviour .headers(header_map) // add spoofed headers to emulate human behaviour
.send() .send()
.await? .await?

View File

@ -0,0 +1,8 @@
#[derive(Debug)]
pub enum ReqwestError{
NotFound,
Timeout,
Forbidden,
AccessDenied,
TooManyRequests
}

View File

@ -1,2 +1,3 @@
pub mod duckduckgo; pub mod duckduckgo;
pub mod engine_models;
pub mod searx; pub mod searx;