Merge pull request #474 from chowder/fix-user-agent

Set User-Agent header in proxied media requests to match currently spoofed device
This commit is contained in:
Matthew Esposito
2025-09-09 13:57:34 -04:00
committed by GitHub
2 changed files with 13 additions and 1 deletions

View File

@@ -165,6 +165,12 @@ async fn stream(url: &str, req: &Request<Body>) -> Result<Response<Body>, 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

View File

@@ -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<String, String>,
headers: HashMap<String, String>,
user_agent: String,
}
impl Device {
@@ -230,7 +235,7 @@ impl Device {
// Android device headers
let headers: HashMap<String, String> = 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 {