Skip to content

Commit be63666

Browse files
authored
feat: support custom UserAgent (#133)
1 parent ee04a13 commit be63666

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/no-dead-link.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const DEFAULT_OPTIONS = {
2020
interval: 500, // The length of time in milliseconds before the interval count resets. Must be finite. [Experimental]
2121
intervalCap: 8, // The max number of runs in the given interval of time. [Experimental]
2222
keepAlive: false, // {boolean} if it is true, use keepAlive for checking request [Experimental]
23+
userAgent: 'textlint-rule-no-dead-link/1.0' // {String} a UserAgent
2324
};
2425

2526
// Adopted from http://stackoverflow.com/a/3809435/951517
@@ -120,7 +121,7 @@ const createFetchWithRuleDefaults = (ruleOptions) => {
120121
// to avoid ECONNRESET error
121122
// https://github.com/textlint-rule/textlint-rule-no-dead-link/issues/111
122123
headers: {
123-
'User-Agent': 'textlint-rule-no-dead-link/1.0',
124+
'User-Agent': ruleOptions.userAgent,
124125
'Accept': '*/*',
125126
// Same host for target url
126127
// https://github.com/textlint-rule/textlint-rule-no-dead-link/issues/111

test/no-dead-link.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ tester.run('no-dead-link', rule, {
106106
ignoreRedirects: true,
107107
},
108108
},
109+
// https://github.com/textlint-rule/textlint-rule-no-dead-link/issues/128
110+
{
111+
text: 'should treat 200 OK. It requires browser-like User-Agent: https://issues.jenkins-ci.org/browse/JENKINS-59261',
112+
options: {
113+
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'
114+
}
115+
}
109116
],
110117
invalid: [
111118
{

0 commit comments

Comments
 (0)