diff --git a/src/client.rs b/src/client.rs index 76369cad..716dc0eb 100644 --- a/src/client.rs +++ b/src/client.rs @@ -165,6 +165,12 @@ async fn stream(url: &str, req: &Request) -> Result, String } } + // Add User-Agent header of the currently spoofed device + { + let client = OAUTH_CLIENT.load_full(); + builder = builder.header("User-Agent", client.user_agent()); + } + let stream_request = builder.body(Body::empty()).map_err(|_| "Couldn't build empty body in stream".to_string())?; client diff --git a/src/oauth.rs b/src/oauth.rs index 9654e0c8..9fb2fd5b 100644 --- a/src/oauth.rs +++ b/src/oauth.rs @@ -148,6 +148,10 @@ impl Oauth { Ok(()) } + + pub fn user_agent(&self) -> &str { + &self.device.user_agent + } } #[derive(Debug)] @@ -209,6 +213,7 @@ struct Device { oauth_id: String, initial_headers: HashMap, headers: HashMap, + user_agent: String, } impl Device { @@ -230,7 +235,7 @@ impl Device { // Android device headers let headers: HashMap = HashMap::from([ - ("User-Agent".into(), android_user_agent), + ("User-Agent".into(), android_user_agent.clone()), ("x-reddit-retry".into(), "algo=no-retries".into()), ("x-reddit-compression".into(), "1".into()), ("x-reddit-qos".into(), qos), @@ -246,6 +251,7 @@ impl Device { oauth_id: REDDIT_ANDROID_OAUTH_CLIENT_ID.to_string(), headers: headers.clone(), initial_headers: headers, + user_agent: android_user_agent, } } fn new() -> Self {