reachable-url 2.1.1 → 2.1.3
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 +1 -1
- package/index.js +10 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -79,7 +79,7 @@ The [got response](https://github.com/sindresorhus/got#response), plus `requestU
|
|
|
79
79
|
|
|
80
80
|
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
81
|
|
|
82
|
-
A `206` that did answer the range is reported as the `200` it stands for, with `content-length` taken from `content-range`.
|
|
82
|
+
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
83
|
|
|
84
84
|
### reachableUrl.isReachable(response)
|
|
85
85
|
|
package/index.js
CHANGED
|
@@ -126,27 +126,29 @@ const reachableUrl = async (url, { maxBody = 0, ...opts } = {}) => {
|
|
|
126
126
|
redirectStatusCodes.push(res.statusCode)
|
|
127
127
|
})
|
|
128
128
|
|
|
129
|
+
// An `afterResponse` retry resolves with the final response without emitting
|
|
130
|
+
// another outer `response` event, so the promise result supersedes the
|
|
131
|
+
// listener's. The error carries one when nothing else did, as MaxRedirects does.
|
|
129
132
|
let errorResponse
|
|
130
133
|
try {
|
|
131
|
-
await req
|
|
134
|
+
response = await req
|
|
132
135
|
} catch (error) {
|
|
133
136
|
errorResponse = error.response
|
|
134
137
|
}
|
|
135
138
|
|
|
136
|
-
// A retried or cancelled request settles with the attempt before it, whose body
|
|
137
|
-
// is not this response's, so a response we saw outranks the error's. The error
|
|
138
|
-
// still carries one when nothing else did, as MaxRedirects does.
|
|
139
139
|
const resolvedResponse = toResponse(response ?? errorResponse)
|
|
140
140
|
|
|
141
|
+
// A satisfied range stands for the whole entity only when the total size is
|
|
142
|
+
// known. `bytes 0-0/*` (or any non-numeric total) must not become
|
|
143
|
+
// `content-length: *`, which is not a length and replaces a valid partial one.
|
|
141
144
|
if (resolvedResponse.statusCode === 206) {
|
|
142
145
|
const contentRange = resolvedResponse.headers['content-range']
|
|
143
146
|
if (typeof contentRange === 'string') {
|
|
144
|
-
|
|
145
|
-
if (
|
|
146
|
-
contentLength = contentLength[contentLength.length - 1]
|
|
147
|
+
const total = contentRange.split('/').pop()
|
|
148
|
+
if (/^\d+$/.test(total)) {
|
|
147
149
|
resolvedResponse.statusCode = 200
|
|
148
150
|
resolvedResponse.statusMessage = 'OK'
|
|
149
|
-
resolvedResponse.headers['content-length'] =
|
|
151
|
+
resolvedResponse.headers['content-length'] = total
|
|
150
152
|
resolvedResponse.headers['content-range'] = undefined
|
|
151
153
|
}
|
|
152
154
|
}
|
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.3",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "josefrancisco.verdu@gmail.com",
|