Send requests with human User-Agent header to reduce false positives by jakejarvis · Pull Request #134 · JustinBeckwith/linkinator · GitHub
Skip to content

Send requests with human User-Agent header to reduce false positives - #134

Merged
JustinBeckwith merged 5 commits into
JustinBeckwith:masterfrom
jakejarvis:user-agent
Oct 13, 2020
Merged

JustinBeckwith merged 5 commits into
JustinBeckwith:masterfrom
jakejarvis:user-agent

Conversation

@jakejarvis

Copy link
Copy Markdown
Contributor

There might be a better way to do this, but after some quick testing I've found specifying a User-Agent header that resembles a human (i.e. Chrome on macOS) drastically cut down on non-404 errors (401, 403, 502, etc.).

I added this quickly without much familiarity with the code (did run test and fix, though) so feel free to make/suggest a better implementation. Maybe it's worth making the specific agent string customizable via an option/flag too, but I can't think of a scenario where that would really be necessary?

Thanks! :)

…tives.

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36
@pjoulot

pjoulot commented Feb 3, 2020

Copy link
Copy Markdown

@JustinBeckwith JustinBeckwith added the enhancement New feature or request label Feb 3, 2020
@JustinBeckwith

Copy link
Copy Markdown
Owner

I love the idea, but I'm just a little bit scared that it's going to get folks IPs banned :) Usually not respecting robots.txt, and faking out the user agent can get you into a little trouble. I'm not saying no, just saying I probably need to do a bit of research.

@pjoulot

pjoulot commented Feb 3, 2020 •

Copy link
Copy Markdown

If we add it as an argument, it gives the choice to the people to use it or not.
Honestly so many websites return an error code when not using a fake user-agent, I definitely need something otherwise the results of linkinator are half wrong.
And we could by default send a custom Linkinator User-Agent because some websites might simply block if it is not set.

@JustinBeckwith JustinBeckwith left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This generally looks good. Could I trouble you to add a test to validate the header is sent?

Comment thread src/index.ts
let res = await gaxios.request<string>({
method: opts.crawl ? 'GET' : 'HEAD',
url: opts.url.href,
headers: {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's define this once, globally, and then use it in both places where we need it.

@JustinBeckwith JustinBeckwith added needs work and removed enhancement New feature or request labels Feb 9, 2020
@JustinBeckwith

Copy link
Copy Markdown
Owner

👋 @jakejarvis this is something I'd love to land! Any way I could trouble you for a test?

@jakejarvis

Copy link
Copy Markdown
Contributor Author

@JustinBeckwith Of course, really sorry for neglecting this! Will re-visit today 😊

@JustinBeckwith
JustinBeckwith merged commit 9a32354 into JustinBeckwith:master Oct 13, 2020
@github-actions

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants