MOCK API for tests
This commit is contained in:
@@ -7,7 +7,6 @@ use serde_json::json;
|
||||
pub struct FlareSolverrRequest {
|
||||
pub cmd: String,
|
||||
pub url: String,
|
||||
pub session: String,
|
||||
pub maxTimeout: u32,
|
||||
}
|
||||
|
||||
@@ -49,21 +48,24 @@ struct FlareSolverrResponse {
|
||||
version: String,
|
||||
}
|
||||
pub struct Flaresolverr {
|
||||
url: String,
|
||||
session: String
|
||||
url: String
|
||||
}
|
||||
impl Flaresolverr {
|
||||
pub fn new(url: String) -> Self {
|
||||
Flaresolverr {
|
||||
url: url,
|
||||
session: "hottub".to_string() }
|
||||
url: url
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn solve(
|
||||
&self,
|
||||
request: FlareSolverrRequest,
|
||||
) -> Result<String, Box<dyn std::error::Error>> {
|
||||
let client = Client::new();
|
||||
let client = Client::builder()
|
||||
.proxy(Proxy::https("http://192.168.0.101:8080").unwrap())
|
||||
.proxy(Proxy::http("http://192.168.0.101:8080").unwrap())
|
||||
.danger_accept_invalid_certs(true)
|
||||
.build()?;
|
||||
|
||||
let response = client
|
||||
.post("http://192.168.0.103:8191/v1")
|
||||
@@ -71,12 +73,12 @@ impl Flaresolverr {
|
||||
.json(&json!({
|
||||
"cmd": request.cmd,
|
||||
"url": request.url,
|
||||
"session": request.session,
|
||||
"maxTimeout": request.maxTimeout,
|
||||
}))
|
||||
.send().await?;
|
||||
|
||||
let body: FlareSolverrResponse = response.json::<FlareSolverrResponse>().await?;
|
||||
println!("FlareSolverr response: {:?}, {}", body.status, body.solution.response.len());
|
||||
Ok(body.solution.response)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user