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

Allow to pass custom headers to http-transport in niljs #180

Merged
merged 1 commit into from
Feb 7, 2025

Conversation

ukorvl
Copy link
Member

@ukorvl ukorvl commented Feb 5, 2025

This pull request introduces several changes to enhance the handling of HTTP headers in the RPC client and transport layer. The most important changes include adding support for custom headers, validating headers, and updating the relevant tests.

Enhancements to HTTP headers handling:

  • niljs/src/rpc/rpcClient.ts: Introduced an optional headers parameter in the RPCClientOptions type and updated the createRPCClient function to include these headers in the HTTP transport configuration. Added a call to isValidHttpHeaders to validate the headers. [1] [2]
  • niljs/src/transport/HttpTransport.ts: Updated the HttpTransport class constructor to accept and pass the headers parameter to the createRPCClient function.
  • niljs/src/transport/types/IHttpTransportConfig.ts: Added an optional headers property to the IHttpTransportConfig type to support custom headers in the transport configuration.

Validation and utility functions:

  • niljs/src/utils/rpc.ts: Added the isValidHttpHeaders function to validate the structure and values of the provided headers. This function ensures that headers are either strings or arrays of strings.

Testing improvements:

  • niljs/src/rpc/rpcClient.test.ts: Added new tests to verify the creation of an RPC client with custom headers and to ensure that invalid headers throw an error.

Copy link

@KlonD90 KlonD90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valudator has expanded option of types like support of arrays, but we don't have it on typing. I think that we could omit validation or update typing here.

Copy link

@KlonD90 KlonD90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ukorvl ukorvl added this pull request to the merge queue Feb 7, 2025
Merged via the queue into main with commit bfd6e4d Feb 7, 2025
13 checks passed
@ukorvl ukorvl deleted the allow-pass-custom-headers-niljs branch February 7, 2025 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
niljs Related to niljs client library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants