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:
parent
318be6ef7e
commit
019b3322e7
@ -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?
|
||||||
|
8
src/engines/engine_models.rs
Normal file
8
src/engines/engine_models.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#[derive(Debug)]
|
||||||
|
pub enum ReqwestError{
|
||||||
|
NotFound,
|
||||||
|
Timeout,
|
||||||
|
Forbidden,
|
||||||
|
AccessDenied,
|
||||||
|
TooManyRequests
|
||||||
|
}
|
@ -1,2 +1,3 @@
|
|||||||
pub mod duckduckgo;
|
pub mod duckduckgo;
|
||||||
|
pub mod engine_models;
|
||||||
pub mod searx;
|
pub mod searx;
|
||||||
|
Loading…
Reference in New Issue
Block a user