Skip to content

Commit

Permalink
Send User-Agent headers
Browse files Browse the repository at this point in the history
By doing this we avoid lots of 403 responses.
  • Loading branch information
mattias-p committed Jun 13, 2023
1 parent 1412abe commit b37b4b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ and this project adheres to [Semantic Versioning].

### Added
- New --link-only flag ([#30], courtesy of [@egrieco]).
- Support links to markdown headings with inline code (backticks).
- New tag CASE_FRAG for fragments that match only case-insensitively.
- Avoid lots of 403 responses by including User-Agent header in HTTP requests.
- Support links to markdown headings with inline code (backticks).

### Other
- Introduce GitHub Actions for push and pull\_request ([#27]), courtesy of [@sanxiyn].
Expand Down
6 changes: 5 additions & 1 deletion src/linky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ impl Client {
let redirects = sync::Arc::new(sync::Mutex::new(vec![]));
let redirects_clone = redirects.clone();
let inner = reqwest::blocking::Client::builder()
.user_agent("linky")
.redirect(reqwest::redirect::Policy::custom(move |attempt| {
let mut redirects_guard = redirects_clone.lock().unwrap();
redirects_guard.push((attempt.status(), attempt.url().clone()));
Expand All @@ -216,7 +217,10 @@ impl Client {

pub fn new_follow() -> Self {
let redirects = sync::Arc::new(sync::Mutex::new(vec![]));
let inner = reqwest::blocking::Client::builder().build().unwrap();
let inner = reqwest::blocking::Client::builder()
.user_agent("linky")
.build()
.unwrap();

Client { inner, redirects }
}
Expand Down

0 comments on commit b37b4b7

Please sign in to comment.