Skip to content

Commit

Permalink
Add the user agent option.
Browse files Browse the repository at this point in the history
  • Loading branch information
lsk569937453 committed May 15, 2024
1 parent 4c244ad commit 6e24070
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ struct Cli {
#[arg(short = 'c', long)]
certificate_path_option: Option<String>,

/// The User Agent.
#[arg(short = 'A', long)]
user_agent_option: Option<String>,

/// The downloading file path .
#[arg(global = true, short = 'o', long, default_missing_value = "none")]
file_path_option: Option<String>,
Expand Down Expand Up @@ -248,9 +252,12 @@ async fn do_request(cli: Cli) -> Result<(), anyhow::Error> {
"host",
HeaderValue::from_str(uri.host().ok_or(anyhow!("no host"))?)?,
);
let user_agent = cli
.user_agent_option
.unwrap_or(format!("rcur/{}", env!("CARGO_PKG_VERSION").to_string()));
request
.headers_mut()
.append("User-Agent", HeaderValue::from_str("rcurl/0.0.6")?);
.append("User-Agent", HeaderValue::from_str(&user_agent)?);
for x in cli.headers {
let split: Vec<String> = x.splitn(2, ':').map(|s| s.to_string()).collect();
if split.len() == 2 {
Expand Down

0 comments on commit 6e24070

Please sign in to comment.