Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for custom http and https agents #966

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/bee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@
timeout: options?.timeout ?? false,
headers: options?.headers,
onRequest: options?.onRequest,
httpAgent: options?.httpAgent,
httpsAgent: options?.httpsAgent,
}
}

Expand Down Expand Up @@ -437,7 +439,7 @@
'manifest',
)
} else if (isReadable(data) && options?.tag && !options.size) {
// TODO: Needed until https://github.com/ethersphere/bee/issues/2317 is resolved

Check warning on line 442 in src/bee.ts

View workflow job for this annotation

GitHub Actions / check (16.x)

Unexpected 'todo' comment: 'TODO: Needed until...'
const result = await bzz.uploadFile(
this.getRequestOptionsForCall(requestOptions),
data,
Expand Down Expand Up @@ -826,7 +828,7 @@
await this.makeFeedReader(type, canonicalTopic, canonicalOwner).download()

return true
} catch (e: any) {

Check warning on line 831 in src/bee.ts

View workflow job for this annotation

GitHub Actions / check (16.x)

Unexpected any. Specify a different type
if (e?.status === 404 || e?.status === 500) {
return false
}
Expand Down Expand Up @@ -1930,7 +1932,7 @@
if (stamp.usable) {
return
}
} catch (error: any) {}

Check warning on line 1935 in src/bee.ts

View workflow job for this annotation

GitHub Actions / check (16.x)

Unexpected any. Specify a different type

Check warning on line 1935 in src/bee.ts

View workflow job for this annotation

GitHub Actions / check (16.x)

Empty block statement

await System.sleepMillis(TIME_STEP)
}
Expand Down
2 changes: 2 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
timeout?: number | false
headers?: Record<string, string>
onRequest?: (request: BeeRequest) => void
httpAgent?: any

Check warning on line 94 in src/types/index.ts

View workflow job for this annotation

GitHub Actions / check (16.x)

Unexpected any. Specify a different type
httpsAgent?: any

Check warning on line 95 in src/types/index.ts

View workflow job for this annotation

GitHub Actions / check (16.x)

Unexpected any. Specify a different type
}

export interface BeeOptions extends BeeRequestOptions {
Expand Down
Loading