diff --git a/src/subreddit.rs b/src/subreddit.rs index 35b4fde..ea57322 100644 --- a/src/subreddit.rs +++ b/src/subreddit.rs @@ -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; diff --git a/src/utils.rs b/src/utils.rs index 102c0e7..6a8da60 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -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 { 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 { @@ -433,7 +434,7 @@ pub async fn request(path: &str) -> Result { // } // 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