Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ impl Oauth {

Ok(())
}

pub fn user_agent(&self) -> &str {
&self.device.user_agent
}
}

#[derive(Debug)]
Expand Down Expand Up @@ -209,6 +213,7 @@ struct Device {
oauth_id: String,
initial_headers: HashMap<String, String>,
headers: HashMap<String, String>,
user_agent: String,
}

impl Device {
Expand All @@ -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),
Expand All @@ -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 {
Expand Down
Loading