Skip to content

Commit 914fd5d

Browse files
committed
fix: add user agent to requests to prevent 403 error
1 parent ebe97bf commit 914fd5d

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "reddownload"
3-
version = "0.2.2"
3+
version = "0.2.3"
44
edition = "2021"
55
license = "MIT"
66
authors = ["Neil Bryson Cargamento <neilbrysonmc@gmail.com>"]

src/main.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ async fn main() -> Result<()> {
2727
let args: Cli = Cli::parse();
2828
let json_url = format!("{}.json", args.url);
2929
let timeout = Duration::new(20, 0);
30-
let client = ClientBuilder::new().timeout(timeout).build()?;
30+
let client = ClientBuilder::new()
31+
.timeout(timeout)
32+
.user_agent(USER_AGENT)
33+
.build()?;
3134
let check_url_response = client.head(&json_url).send().await?;
3235

3336
return if check_url_response.status().is_success() {

src/utils.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use crate::USER_AGENT;
21
use anyhow::{anyhow, Context, Result};
3-
use reqwest::{header, Client};
2+
use reqwest::Client;
43
use std::fs;
54
use std::io::{copy, Cursor};
65
use std::path::{Path, PathBuf};
@@ -16,7 +15,6 @@ pub async fn download_file(
1615
) -> Result<PathBuf> {
1716
let response = client
1817
.get(url)
19-
.header(header::USER_AGENT, USER_AGENT)
2018
.header("Content-Type", content_type)
2119
.send()
2220
.await?;

0 commit comments

Comments
 (0)