Skip to content

Commit

Permalink
Add fetch options with default size and timeout limits.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlongley committed Mar 17, 2024
1 parent c3744b5 commit 14f270d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# bedrock-jsonld-document-loader ChangeLog

## 5.0.0 - 2024-mm-dd

### Changed
- **BREAKING**: Add fetch options with default size and timeout limits
(16 KiB and 5 seconds, respectively) for `httpHandlerClient`.

## 4.0.0 - 2023-09-18

### Changed
Expand Down
15 changes: 15 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*!
* Copyright (c) 2024 Digital Bazaar, Inc. All rights reserved.
*/
import {config} from '@bedrock/core';

const cfg = config['jsonld-document-loader'] = {};

cfg.httpClientHandler = {
fetchOptions: {
// max size for fetched documents (in bytes, ~16 KiB)
size: 16384,
// timeout in ms for fetching a document
timeout: 5000
}
};
10 changes: 8 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/*!
* Copyright (c) 2019-2022 Digital Bazaar, Inc. All rights reserved.
* Copyright (c) 2019-2024 Digital Bazaar, Inc. All rights reserved.
*/
import {agent} from '@bedrock/https-agent';
import {config} from '@bedrock/core';
import {httpClient} from '@digitalbazaar/http-client';
import {JsonLdDocumentLoader} from 'jsonld-document-loader';

import './config.js';

const jdl = new JsonLdDocumentLoader();

export const httpClientHandler = {
Expand All @@ -18,9 +21,12 @@ export const httpClientHandler = {
if(!url.startsWith('http')) {
throw new Error('NotFoundError');
}
const {
httpClientHandler: {fetchOptions}
} = config['jsonld-document-loader'];
let result;
try {
result = await httpClient.get(url, {agent});
result = await httpClient.get(url, {...fetchOptions, agent});
} catch(e) {
throw new Error('NotFoundError');
}
Expand Down

0 comments on commit 14f270d

Please sign in to comment.