-
Notifications
You must be signed in to change notification settings - Fork 105
Revised PR 763 - Add API key support for JSON-RPC requests #827
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe update introduces a new optional parameter, Changes
Sequence Diagram(s)sequenceDiagram
participant C as Client
participant J as JsonRpcBase
participant N as XRPL Node
C->>J: Initialize with custom headers
C->>J: Send JSON-RPC request (optionally with per-request headers)
J->>N: Forward request including headers
N-->>J: Return response
J-->>C: Deliver response
Poem
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🔇 Additional comments (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
Revised PR 763
#763
This change allows
JsonRpcBase
to include custom HTTP headers when connecting to XRPL nodes that require authentication or metadata. The__init__
method now accepts a headers argument, which is stored as an attribute and merged with any per-request headers passed to_request_impl
.• Updated the _request_impl method to merge default and request-specific headers.
• Added a headers parameter to the
__init__
method for flexible instantiation.• This change was tested by connecting to a private XRPL server that required authentication using a custom header.
High Level Overview of Change
This PR introduces support for custom header injection in the
JsonRpcBase
class. An optional headers parameter has been added to the__init__
method, allowing users to specify HTTP headers to include in eachJSON-RPC
request. The_request_impl
method also accepts an optional headers argument to override or add headers on a per-request basis.This makes it easier to integrate
xrpl-py
with private infrastructure providers and secure environments, while maintaining full backward compatibility.Context of Change
This change is driven by the increasing use of XRPL infrastructure that relies on API key or header-based authentication—such as rate-limited services or internal infrastructure. Previously,
JsonRpcBase
did not support adding HTTP headers, limiting its usefulness in many production environments.By making this update in the shared
json_rpc_base.py
layer, all inheriting classes benefit from the new feature. It allows for greater flexibility without impacting users who do not require any headers. Additionally, the per-request header support allows for advanced use cases like dynamic tokens, session headers, or monetized access.Type of Change
Did you update CHANGELOG.md?
Test Plan
The change can be tested by:
• Connecting to a private XRPL server that requires authentication using a custom header and verifying that requests are processed successfully.
• Ensuring compatibility with public nodes by omitting the headers parameter, confirming that no issues arise when using unauthenticated connections.
• Passing request-specific headers to
_request_impl
and verifying that they are correctly merged with any global headers.• Confirming that all existing requests function identically when headers are not used.
Future Tasks
Future tasks related to this PR could include:
• Elevating header support to the top-level
Client
class to ensure WebSocket clients can also benefit from custom headers.