Skip to content

Commit 6f41558

Browse files
authored
fix(rule): add default Host: header (#117)
* fix(rule): add default Host: header * chore(deps): use node-fetch directory
1 parent 89b2902 commit 6f41558

File tree

4 files changed

+14
-34
lines changed

4 files changed

+14
-34
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"dependencies": {
3131
"fs-extra": "^8.0.1",
3232
"get-url-origin": "^1.0.1",
33-
"isomorphic-fetch": "^2.2.1",
3433
"minimatch": "^3.0.4",
34+
"node-fetch": "^2.6.0",
3535
"textlint-rule-helper": "^2.1.1"
3636
},
3737
"lint-staged": {

src/no-dead-link.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { RuleHelper } from 'textlint-rule-helper';
2-
import fetch from 'isomorphic-fetch';
2+
import fetch from 'node-fetch';
33
import URL from 'url';
44
import fs from 'fs-extra';
55
import minimatch from 'minimatch';
@@ -72,6 +72,7 @@ function isIgnored(uri, ignore = []) {
7272
* @return {{ ok: boolean, redirect?: string, message: string }}
7373
*/
7474
async function isAliveURI(uri, method = 'HEAD') {
75+
const { host } = URL.parse(uri);
7576
const opts = {
7677
method,
7778
// Disable gzip compression in Node.js
@@ -83,13 +84,15 @@ async function isAliveURI(uri, method = 'HEAD') {
8384
// https://github.com/textlint-rule/textlint-rule-no-dead-link/issues/111
8485
headers: {
8586
'User-Agent': 'textlint-rule-no-dead-link/1.0',
86-
'Accept': '*/*'
87+
'Accept': '*/*',
88+
// Same host for target url
89+
// https://github.com/textlint-rule/textlint-rule-no-dead-link/issues/111
90+
'Host': host
8791
},
8892
// Use `manual` redirect behaviour to get HTTP redirect status code
8993
// and see what kind of redirect is occurring
9094
redirect: 'manual',
9195
};
92-
9396
try {
9497
const res = await fetch(uri, opts);
9598

@@ -253,7 +256,7 @@ function reporter(context, options = {}) {
253256
if (typeof node.url === 'undefined') {
254257
return;
255258
}
256-
259+
257260
// [text](http://example.com)
258261
// ^
259262
const index = node.raw.indexOf(node.url) || 0;

test/no-dead-link.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ tester.run('no-dead-link', rule, {
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',
1818
'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>',
19+
'should treat 200 OK. It require User-Agent: https://tools.ietf.org/html/rfc6749',
2020
{
2121
text:
2222
'should be able to check a URL in a plain text: https://example.com/',

yarn.lock

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,12 +1460,6 @@ emoji-regex@^7.0.1:
14601460
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-7.0.3.tgz#933a04052860c85e83c122479c4748a8e4c72156"
14611461
integrity sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==
14621462

1463-
encoding@^0.1.11:
1464-
version "0.1.12"
1465-
resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.12.tgz#538b66f3ee62cd1ab51ec323829d1f9480c74beb"
1466-
dependencies:
1467-
iconv-lite "~0.4.13"
1468-
14691463
end-of-stream@^1.1.0:
14701464
version "1.4.1"
14711465
resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.1.tgz#ed29634d19baba463b6ce6b80a37213eab71ec43"
@@ -2253,10 +2247,6 @@ iconv-lite@^0.4.17:
22532247
version "0.4.19"
22542248
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b"
22552249

2256-
iconv-lite@~0.4.13:
2257-
version "0.4.15"
2258-
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.15.tgz#fe265a218ac6a57cfe854927e9d04c19825eddeb"
2259-
22602250
ignore@^3.3.3:
22612251
version "3.3.7"
22622252
resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.7.tgz#612289bfb3c220e186a58118618d5be8c1bab021"
@@ -2603,7 +2593,7 @@ is-resolvable@^1.0.0:
26032593
dependencies:
26042594
tryit "^1.0.1"
26052595

2606-
is-stream@^1.0.1, is-stream@^1.1.0:
2596+
is-stream@^1.1.0:
26072597
version "1.1.0"
26082598
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
26092599

@@ -2663,13 +2653,6 @@ isobject@^3.0.0, isobject@^3.0.1:
26632653
resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df"
26642654
integrity sha1-TkMekrEalzFjaqH5yNHMvP2reN8=
26652655

2666-
isomorphic-fetch@^2.2.1:
2667-
version "2.2.1"
2668-
resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9"
2669-
dependencies:
2670-
node-fetch "^1.0.1"
2671-
whatwg-fetch ">=0.10.0"
2672-
26732656
isstream@~0.1.2:
26742657
version "0.1.2"
26752658
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
@@ -3213,12 +3196,10 @@ [email protected]:
32133196
object.getownpropertydescriptors "^2.0.3"
32143197
semver "^5.7.0"
32153198

3216-
node-fetch@^1.0.1:
3217-
version "1.6.3"
3218-
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.6.3.tgz#dc234edd6489982d58e8f0db4f695029abcd8c04"
3219-
dependencies:
3220-
encoding "^0.1.11"
3221-
is-stream "^1.0.1"
3199+
node-fetch@^2.6.0:
3200+
version "2.6.0"
3201+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
3202+
integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==
32223203

32233204
node-pre-gyp@^0.6.29:
32243205
version "0.6.32"
@@ -4736,10 +4717,6 @@ vfile@^2.0.0:
47364717
unist-util-stringify-position "^1.0.0"
47374718
vfile-message "^1.0.0"
47384719

4739-
whatwg-fetch@>=0.10.0:
4740-
version "2.0.2"
4741-
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.2.tgz#fe294d1d89e36c5be8b3195057f2e4bc74fc980e"
4742-
47434720
which-module@^2.0.0:
47444721
version "2.0.0"
47454722
resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a"

0 commit comments

Comments
 (0)