Allow to pass custom headers to http-transport in niljs #180
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 optionalheaders
parameter in theRPCClientOptions
type and updated thecreateRPCClient
function to include these headers in the HTTP transport configuration. Added a call toisValidHttpHeaders
to validate the headers. [1] [2]niljs/src/transport/HttpTransport.ts
: Updated theHttpTransport
class constructor to accept and pass theheaders
parameter to thecreateRPCClient
function.niljs/src/transport/types/IHttpTransportConfig.ts
: Added an optionalheaders
property to theIHttpTransportConfig
type to support custom headers in the transport configuration.Validation and utility functions:
niljs/src/utils/rpc.ts
: Added theisValidHttpHeaders
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.