Fix user agent

This commit is contained in:
spikecodes 2021-01-16 15:13:34 -08:00
parent a0bc1732cf
commit 0e48c66b8c
2 changed files with 3 additions and 2 deletions

View File

@ -1,5 +1,5 @@
// CRATES // 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 actix_web::{HttpRequest, HttpResponse, Result};
use askama::Template; use askama::Template;

View File

@ -375,6 +375,7 @@ pub async fn error(msg: String) -> HttpResponse {
// Make a request to a Reddit API and parse the JSON response // Make a request to a Reddit API and parse the JSON response
pub async fn request(path: &str) -> Result<Value, String> { pub async fn request(path: &str) -> Result<Value, String> {
let url = format!("https://www.reddit.com{}", path); let url = format!("https://www.reddit.com{}", path);
let user_agent = format!("web:libreddit:{}", env!("CARGO_PKG_VERSION"));
// Send request using awc // Send request using awc
// async fn send(url: &str) -> Result<String, (bool, String)> { // 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 // 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 // If response is success
Ok(response) => { Ok(response) => {
// Parse the response from Reddit as JSON // Parse the response from Reddit as JSON