Revert to reqwest
This commit is contained in:
parent
9d78266494
commit
759c9fc66b
791
Cargo.lock
generated
791
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -14,7 +14,7 @@ proxy = ["actix-web/rustls", "base64"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
base64 = { version = "0.13.0", optional = true }
|
base64 = { version = "0.13.0", optional = true }
|
||||||
actix-web = "3.2.0"
|
actix-web = "3.2.0"
|
||||||
surf = "2.1.0"
|
reqwest = { version = "0.10", default_features = false, features = ["rustls-tls"] }
|
||||||
askama = "0.8.0"
|
askama = "0.8.0"
|
||||||
serde = "1.0.117"
|
serde = "1.0.117"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
26
src/utils.rs
26
src/utils.rs
@ -3,7 +3,7 @@
|
|||||||
//
|
//
|
||||||
use chrono::{TimeZone, Utc};
|
use chrono::{TimeZone, Utc};
|
||||||
use serde_json::{from_str, Value};
|
use serde_json::{from_str, Value};
|
||||||
use surf::{client, get, middleware::Redirect};
|
// use surf::{client, get, middleware::Redirect};
|
||||||
|
|
||||||
//
|
//
|
||||||
// STRUCTS
|
// STRUCTS
|
||||||
@ -161,20 +161,20 @@ pub async fn request(url: String) -> Result<serde_json::Value, &'static str> {
|
|||||||
// let body = std::str::from_utf8(res.as_ref())?; // .as_ref converts Bytes to [u8]
|
// let body = std::str::from_utf8(res.as_ref())?; // .as_ref converts Bytes to [u8]
|
||||||
|
|
||||||
// --- surf ---
|
// --- surf ---
|
||||||
let req = get(&url).header("User-Agent", "libreddit");
|
// let req = get(&url).header("User-Agent", "libreddit");
|
||||||
let client = client().with(Redirect::new(5));
|
// let client = client().with(Redirect::new(5));
|
||||||
let mut res = client.send(req).await.unwrap();
|
// let mut res = client.send(req).await.unwrap();
|
||||||
let success = res.status().is_success();
|
// let success = res.status().is_success();
|
||||||
let body = res.body_string().await.unwrap();
|
// let body = res.body_string().await.unwrap();
|
||||||
|
|
||||||
dbg!(url.clone());
|
|
||||||
|
|
||||||
// --- reqwest ---
|
// --- reqwest ---
|
||||||
// let res = reqwest::get(&url).await.unwrap();
|
let res = reqwest::get(&url).await.unwrap();
|
||||||
// // Read the status from the response
|
// Read the status from the response
|
||||||
// let success = res.status().is_success();
|
let success = res.status().is_success();
|
||||||
// // Read the body of the response
|
// Read the body of the response
|
||||||
// let body = res.text().await.unwrap();
|
let body = res.text().await.unwrap();
|
||||||
|
|
||||||
|
dbg!(url.clone());
|
||||||
|
|
||||||
// Parse the response from Reddit as JSON
|
// Parse the response from Reddit as JSON
|
||||||
let json: Value = from_str(body.as_str()).unwrap_or(Value::Null);
|
let json: Value = from_str(body.as_str()).unwrap_or(Value::Null);
|
||||||
|
Loading…
Reference in New Issue
Block a user