reachable-url 2.1.2 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -8
- package/index.js +14 -12
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -65,13 +65,7 @@ const response = await reachableUrl('https://example.com/video.mp4', { cache })
|
|
|
65
65
|
response.body // => the whole entity, so it can be cached
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
`cache` needs [@kikobeats/cacheable-request](https://github.com/Kikobeats/cacheable-request):
|
|
69
|
-
|
|
70
|
-
```yaml
|
|
71
|
-
# pnpm-workspace.yaml
|
|
72
|
-
overrides:
|
|
73
|
-
got>cacheable-request: npm:@kikobeats/cacheable-request
|
|
74
|
-
```
|
|
68
|
+
`cache` needs [@kikobeats/cacheable-request](https://github.com/Kikobeats/cacheable-request): upstream [cacheable-request](https://github.com/jaredwray/cacheable/tree/main/packages/cacheable-request) never settles when the origin keeps the connection alive, and no timeout recovers from it. [@kikobeats/got](https://github.com/Kikobeats/got) depends on the fork since 11.8.9, so it works without any configuration. If something in your dependency tree still resolves the upstream package, passing `cache` throws instead of hanging.
|
|
75
69
|
|
|
76
70
|
#### returns
|
|
77
71
|
|
|
@@ -79,7 +73,7 @@ The [got response](https://github.com/sindresorhus/got#response), plus `requestU
|
|
|
79
73
|
|
|
80
74
|
By default the request asks for a single byte (`Range: bytes=0-0`, which [`maxBody`](#maxbody) drops when it wants more). When a server ignores that and starts sending the whole entity, the download is cancelled: the status and headers already say whether the URL is reachable, so `body` is `undefined` on those responses unless [`maxBody`](#maxbody) asked for some of it.
|
|
81
75
|
|
|
82
|
-
A `206` that did answer the range is reported as the `200` it stands for, with `content-length` taken from `content-range`.
|
|
76
|
+
A `206` that did answer the range is reported as the `200` it stands for, with `content-length` taken from a numeric `content-range` total. An unknown total (`bytes 0-0/*`) is left as a `206`.
|
|
83
77
|
|
|
84
78
|
### reachableUrl.isReachable(response)
|
|
85
79
|
|
package/index.js
CHANGED
|
@@ -4,7 +4,7 @@ const { URL } = require('url')
|
|
|
4
4
|
|
|
5
5
|
const RANGE_LENGTH = 1
|
|
6
6
|
|
|
7
|
-
const got = require('got').extend({
|
|
7
|
+
const got = require('@kikobeats/got').extend({
|
|
8
8
|
decompress: false,
|
|
9
9
|
responseType: 'buffer',
|
|
10
10
|
retry: 1,
|
|
@@ -30,15 +30,14 @@ const toResponse = response => ({
|
|
|
30
30
|
|
|
31
31
|
const CACHE_ERROR = `The \`cache\` option needs @kikobeats/cacheable-request.
|
|
32
32
|
|
|
33
|
-
got resolved the unpatched cacheable-request@7, which never settles
|
|
34
|
-
origin keeps the connection alive, and no timeout recovers from it.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
overrides:
|
|
38
|
-
got>cacheable-request: npm:@kikobeats/cacheable-request`
|
|
33
|
+
@kikobeats/got resolved the unpatched cacheable-request@7, which never settles
|
|
34
|
+
when the origin keeps the connection alive, and no timeout recovers from it.
|
|
35
|
+
Upgrade @kikobeats/got to 11.8.9 or later, which depends on the patched fork.`
|
|
39
36
|
|
|
40
37
|
const loadCacheableRequestManifest = () =>
|
|
41
|
-
require(require.resolve('cacheable-request/package.json', {
|
|
38
|
+
require(require.resolve('cacheable-request/package.json', {
|
|
39
|
+
paths: [require.resolve('@kikobeats/got')]
|
|
40
|
+
}))
|
|
42
41
|
|
|
43
42
|
// The override is an alias, which keeps the real package name, so the manifest says
|
|
44
43
|
// which one got resolved. Only a positive match rejects: the lookup can legitimately
|
|
@@ -138,15 +137,17 @@ const reachableUrl = async (url, { maxBody = 0, ...opts } = {}) => {
|
|
|
138
137
|
|
|
139
138
|
const resolvedResponse = toResponse(response ?? errorResponse)
|
|
140
139
|
|
|
140
|
+
// A satisfied range stands for the whole entity only when the total size is
|
|
141
|
+
// known. `bytes 0-0/*` (or any non-numeric total) must not become
|
|
142
|
+
// `content-length: *`, which is not a length and replaces a valid partial one.
|
|
141
143
|
if (resolvedResponse.statusCode === 206) {
|
|
142
144
|
const contentRange = resolvedResponse.headers['content-range']
|
|
143
145
|
if (typeof contentRange === 'string') {
|
|
144
|
-
|
|
145
|
-
if (
|
|
146
|
-
contentLength = contentLength[contentLength.length - 1]
|
|
146
|
+
const total = contentRange.split('/').pop()
|
|
147
|
+
if (/^\d+$/.test(total)) {
|
|
147
148
|
resolvedResponse.statusCode = 200
|
|
148
149
|
resolvedResponse.statusMessage = 'OK'
|
|
149
|
-
resolvedResponse.headers['content-length'] =
|
|
150
|
+
resolvedResponse.headers['content-length'] = total
|
|
150
151
|
resolvedResponse.headers['content-range'] = undefined
|
|
151
152
|
}
|
|
152
153
|
}
|
|
@@ -173,3 +174,4 @@ module.exports = async (url, opts) => {
|
|
|
173
174
|
|
|
174
175
|
module.exports.isReachable = isReachable
|
|
175
176
|
module.exports.assertCacheSupport = assertCacheSupport
|
|
177
|
+
module.exports.loadCacheableRequestManifest = loadCacheableRequestManifest
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "reachable-url",
|
|
3
3
|
"description": "Resolve a URL as fast as possible and report whether the destination is reachable over HTTP.",
|
|
4
4
|
"homepage": "https://github.com/Kikobeats/reachable-url",
|
|
5
|
-
"version": "2.1.
|
|
5
|
+
"version": "2.1.4",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "josefrancisco.verdu@gmail.com",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"url"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"got": "~11.8.
|
|
33
|
+
"@kikobeats/got": "~11.8.9"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@commitlint/cli": "latest",
|