mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-12-22 20:38:22 -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
|
||||
//! number if provided.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::{collections::HashMap, time::Duration};
|
||||
|
||||
use reqwest::header::{HeaderMap, CONTENT_TYPE, COOKIE, REFERER, USER_AGENT};
|
||||
use scraper::{Html, Selector};
|
||||
@ -57,6 +57,7 @@ pub async fn results(
|
||||
// TODO: Write better error handling code to handle no results case.
|
||||
let results: String = reqwest::Client::new()
|
||||
.get(url)
|
||||
.timeout(Duration::from_secs(30))
|
||||
.headers(header_map) // add spoofed headers to emulate human behaviour
|
||||
.send()
|
||||
.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 engine_models;
|
||||
pub mod searx;
|
||||
|
Loading…
Reference in New Issue
Block a user