Skip to content

Commit bfb672f

Browse files
authored
fix(rule): add default UserAgent and Accept Header (#116)
1 parent bc7c8e4 commit bfb672f

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/no-dead-link.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ async function isAliveURI(uri, method = 'HEAD') {
7878
// to avoid the zlib's "unexpected end of file" error
7979
// https://github.com/request/request/issues/2045
8080
compress: false,
81+
// Some website require UserAgent and Accept header
82+
// to avoid ECONNRESET error
83+
// https://github.com/textlint-rule/textlint-rule-no-dead-link/issues/111
84+
headers: {
85+
'User-Agent': 'textlint-rule-no-dead-link/1.0',
86+
'Accept': '*/*'
87+
},
8188
// Use `manual` redirect behaviour to get HTTP redirect status code
8289
// and see what kind of redirect is occurring
8390
redirect: 'manual',

test/no-dead-link.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ tester.run('no-dead-link', rule, {
1515
'should be able to check a URL in Markdown: https://example.com/',
1616
'should success with retrying on error: [npm results for textlint](https://www.npmjs.com/search?q=textlint)',
1717
'should treat 200 OK as alive: https://httpstat.us/200',
18+
'should treat 200 OK. It require User-Agent: Navigate to [MySQL distribution](https://dev.mysql.com/downloads/mysql/) to install MySQL `5.7`.',
19+
'should treat 200 OK. It require User-Agent: <https://tools.ietf.org/html/rfc6749>',
1820
{
1921
text:
2022
'should be able to check a URL in a plain text: https://example.com/',

0 commit comments

Comments
 (0)