Skip to content

Commit

Permalink
feat: support custom UserAgent (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
yshrsmz committed Jun 19, 2020
1 parent ee04a13 commit be63666
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/no-dead-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const DEFAULT_OPTIONS = {
interval: 500, // The length of time in milliseconds before the interval count resets. Must be finite. [Experimental]
intervalCap: 8, // The max number of runs in the given interval of time. [Experimental]
keepAlive: false, // {boolean} if it is true, use keepAlive for checking request [Experimental]
userAgent: 'textlint-rule-no-dead-link/1.0' // {String} a UserAgent
};

// Adopted from http://stackoverflow.com/a/3809435/951517
Expand Down Expand Up @@ -120,7 +121,7 @@ const createFetchWithRuleDefaults = (ruleOptions) => {
// to avoid ECONNRESET error
// https://github.com/textlint-rule/textlint-rule-no-dead-link/issues/111
headers: {
'User-Agent': 'textlint-rule-no-dead-link/1.0',
'User-Agent': ruleOptions.userAgent,
'Accept': '*/*',
// Same host for target url
// https://github.com/textlint-rule/textlint-rule-no-dead-link/issues/111
Expand Down
7 changes: 7 additions & 0 deletions test/no-dead-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ tester.run('no-dead-link', rule, {
ignoreRedirects: true,
},
},
// https://github.com/textlint-rule/textlint-rule-no-dead-link/issues/128
{
text: 'should treat 200 OK. It requires browser-like User-Agent: https://issues.jenkins-ci.org/browse/JENKINS-59261',
options: {
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36'
}
}
],
invalid: [
{
Expand Down

0 comments on commit be63666

Please sign in to comment.