reachable-url 2.1.2 → 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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/index.js +6 -4
  3. 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
@@ -138,15 +138,17 @@ const reachableUrl = async (url, { maxBody = 0, ...opts } = {}) => {
138
138
 
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
- let contentLength = contentRange.split('/')
145
- if (contentLength.length > 1) {
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'] = contentLength
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.2",
5
+ "version": "2.1.3",
6
6
  "main": "index.js",
7
7
  "author": {
8
8
  "email": "josefrancisco.verdu@gmail.com",