Fix user agent
This commit is contained in:
parent
a0bc1732cf
commit
0e48c66b8c
@ -1,5 +1,5 @@
|
||||
// CRATES
|
||||
use crate::utils::{cookie, error, fetch_posts, format_num, format_url, param, prefs, request, rewrite_url, val, Post, Preferences, Subreddit};
|
||||
use crate::utils::*;
|
||||
use actix_web::{HttpRequest, HttpResponse, Result};
|
||||
use askama::Template;
|
||||
|
||||
|
@ -375,6 +375,7 @@ pub async fn error(msg: String) -> HttpResponse {
|
||||
// Make a request to a Reddit API and parse the JSON response
|
||||
pub async fn request(path: &str) -> Result<Value, String> {
|
||||
let url = format!("https://www.reddit.com{}", path);
|
||||
let user_agent = format!("web:libreddit:{}", env!("CARGO_PKG_VERSION"));
|
||||
|
||||
// Send request using awc
|
||||
// async fn send(url: &str) -> Result<String, (bool, String)> {
|
||||
@ -433,7 +434,7 @@ pub async fn request(path: &str) -> Result<Value, String> {
|
||||
// }
|
||||
|
||||
// Send request using ureq
|
||||
match ureq::get(&url).call() {
|
||||
match ureq::get(&url).set("User-Agent", user_agent.as_str()).call() {
|
||||
// If response is success
|
||||
Ok(response) => {
|
||||
// Parse the response from Reddit as JSON
|
||||
|
Loading…
Reference in New Issue
Block a user