Skip to content

Commit d37c360

Browse files
committed
Update to @digitalbazar/http-client@3.
- Pulls in newer `ky` and `ky-universal` that should address security alerts and provide other improvements. - Newer `ky` will throw errors on redirects even when in `manual` redirect mode. Now using `throwHttpErrors` option to turn off errors. - One of the updated dependencies can cause tests to rewrite redirect `Location` URLs to be relative references. The global `URL` interface is now used to rebuild a full URL for further redirect processing. - Newer `node-forge` will output a one-time warning if code even accesses `response.data`. `@digitalbazar/http-client` will forcefully set `data` *if* it detects a JSON content type. Calling code can't know if that happened, so currently needs to redo content detection to know if JSON `data` can be accessed. This is an issue for sites where JSON-LD was requested but the response is non-JSON with a `Link` header pointing to the JSON-LD.
1 parent ed0ff48 commit d37c360

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# jsonld ChangeLog
22

3+
## 5.3.0 - 2022-xx-xx
4+
5+
### Changed
6+
- Update to `@digitalbazaar/http-client@3`:
7+
- Pulls in newer `ky` and `ky-universal` that should address security alerts
8+
and provide other improvements.
9+
- Use global `URL` interface to handle relative redirects.
10+
311
## 5.2.0 - 2021-04-07
412

513
### Changed

lib/documentLoaders/node.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ module.exports = ({
143143
});
144144
}
145145
redirects.push(url);
146-
return loadDocument(location, redirects);
146+
// location can be relative, turn into full url
147+
const nextUrl = new URL(location, url).href;
148+
return loadDocument(nextUrl, redirects);
147149
}
148150

149151
// cache for each redirected URL
@@ -163,7 +165,12 @@ module.exports = ({
163165

164166
async function _fetch({url, headers, strictSSL, httpAgent, httpsAgent}) {
165167
try {
166-
const options = {headers, redirect: 'manual'};
168+
const options = {
169+
headers,
170+
redirect: 'manual',
171+
// ky specific to avoid redirects throwing
172+
throwHttpErrors: false
173+
};
167174
const isHttps = url.startsWith('https:');
168175
if(isHttps) {
169176
options.agent =
@@ -174,7 +181,13 @@ async function _fetch({url, headers, strictSSL, httpAgent, httpsAgent}) {
174181
}
175182
}
176183
const res = await httpClient.get(url, options);
177-
return {res, body: res.data};
184+
// @digitalbazaar/http-client may use node-fetch, which can output
185+
// a warning if response.data is accessed and no json was parsed.
186+
// Used here is the same type detection logic so the data field is
187+
// accessed only if the client likely tried to parse JSON.
188+
const contentType = res.headers.get('content-type');
189+
const hasJson = contentType && contentType.includes('json');
190+
return {res, body: hasJson ? res.data : null};
178191
} catch(e) {
179192
// HTTP errors have a response in them
180193
// ky considers redirects HTTP errors

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"lib/**/*.js"
3030
],
3131
"dependencies": {
32-
"@digitalbazaar/http-client": "^1.1.0",
32+
"@digitalbazaar/http-client": "^3.0.1",
3333
"canonicalize": "^1.0.1",
3434
"lru-cache": "^6.0.0",
3535
"rdf-canonize": "^3.0.0"

0 commit comments

Comments
 (0)