From d71c9d27e2ddf5603b565399fb372eda7db3a6ea Mon Sep 17 00:00:00 2001 From: Cafe137 Date: Thu, 24 Oct 2024 18:55:18 +0200 Subject: [PATCH] feat: add support for custom http and https agents --- README.md | 12 ++++++++++++ src/bee.ts | 2 ++ src/types/index.ts | 2 ++ 3 files changed, 16 insertions(+) diff --git a/README.md b/README.md index 76b5d988..5912f138 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,18 @@ const bee = new Bee('http://localhost:1633') const uploadResult = await bee.uploadFilesFromDirectory(batchId, './path/to/gallery/') ``` +### Customize http/https agent and headers + +```js +const bee = new Bee('http://localhost:1633', { + httpAgent: new http.Agent({ keepAlive: true }), + httpsAgent: new https.Agent({ keepAlive: true }), + headers: { + Authorization: 'Basic ' + Buffer.from('username:password').toString('base64'), + }, +}) +``` + [**Check out our examples repo for some more ideas on how to use `bee-js`**](https://github.com/ethersphere/examples-js) ## Documentation diff --git a/src/bee.ts b/src/bee.ts index 09ad0608..9a39066a 100644 --- a/src/bee.ts +++ b/src/bee.ts @@ -184,6 +184,8 @@ export class Bee { timeout: options?.timeout ?? false, headers: options?.headers, onRequest: options?.onRequest, + httpAgent: options?.httpAgent, + httpsAgent: options?.httpsAgent, } } diff --git a/src/types/index.ts b/src/types/index.ts index b4d8acea..d59dee35 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -91,6 +91,8 @@ export type BeeRequestOptions = { timeout?: number | false headers?: Record onRequest?: (request: BeeRequest) => void + httpAgent?: any + httpsAgent?: any } export interface BeeOptions extends BeeRequestOptions {