-
Notifications
You must be signed in to change notification settings - Fork 134
feat: allow modifying trustless-gateway fetch #751
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: allow modifying trustless-gateway fetch #751
Conversation
Added an optional `headers` property to the `TrustlessGatewayBlockBroker` and `TrustlessGatewaySession` options, allowing users to specify custom headers for HTTP requests. Changes include: * Added `headers` property to `TrustlessGatewayBlockBroker` and `TrustlessGatewaySession` options * Updated `findHttpGatewayProviders` function to accept an optional `headers` object * Passed `headers` object to `TrustlessGateway` constructor * Updated `TrustlessGateway` constructor to accept an optional `headers` object * Added `headers` to HTTP request options in `TrustlessGateway`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self review
@pcfreak30 can you confirm this will work for your use-case? cc @achingbrain |
At a glance, yes. primary use case is a JWT. |
I'll need to look further into the chrome failures later. I was able to reproduce these locally fixed with |
ping @achingbrain and @2color for review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! LGTM.
I'd add an example to the helia README (not a blocker. we can do it in a followup)
Happy to see this get merged in :). Thanks for collaborating. |
@@ -33,7 +33,7 @@ export function filterNonHTTPMultiaddrs (multiaddrs: Multiaddr[], allowInsecure: | |||
}) | |||
} | |||
|
|||
export async function * findHttpGatewayProviders (cid: CID, routing: Routing, logger: ComponentLogger, allowInsecure: boolean, allowLocal: boolean, options?: AbortOptions): AsyncGenerator<TrustlessGateway> { | |||
export async function * findHttpGatewayProviders (cid: CID, routing: Routing, logger: ComponentLogger, allowInsecure: boolean, allowLocal: boolean, transformRequestInit?: TransformRequestInit, options: AbortOptions = {}): AsyncGenerator<TrustlessGateway> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that it's optional, can transformRequestInit
go in the options object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Small nit about the optional arg.
* origin/main: chore: use peer id parsing function from libp2p (#762) feat: add republish signed ipns records (#745) fix: use bytestream methods to add byte streams (#758) chore: bump codecov/codecov-action from 5.3.1 to 5.4.0 (#752) feat: allow modifying trustless-gateway fetch (#751) fix: align implicit default ttl with specs (#749) docs: add spell checker to ci (#743) chore: Update FUNDING.json for Optimism RPF (#746)
Title
feat: allow modifying trustless-gateway fetch
Description
This PR allows consumers to modify headers and any other RequestInit options that trustless-gateways use when making a fetch request to a trustless gateway.
This allows consumers to add JWT tokens to the request, or modifying the request in a variety of other ways. If the user does not modify the requestInit object, the default behavior is to use the same requestInit object that was used prior to this PR.
Fixes #659
Replaces #732
Notes & open questions
Change checklist