Skip to content

Conversation

@samuelarogbonlo
Copy link
Contributor

@samuelarogbonlo samuelarogbonlo commented Nov 26, 2025

Summary

Implements request and response interceptor pattern for RPC clients, enabling rate limiting, logging, and other middleware functionality for WebSocket/IPC connections.

Motivation

Fixes #33221

Users need a way to implement rate limiting and other cross-cutting concerns for RPC clients, particularly for WebSocket/WSS connections. This was requested in [issue link].

Changes

  • Added RequestInterceptor and ResponseInterceptor types
  • Implemented WithRequestInterceptor() and WithResponseInterceptor() client options
  • Hooked interceptors into all RPC methods: CallContext, BatchCallContext, Notify, Subscribe
  • Request interceptors run before sending (ideal for rate limiting, validation)
  • Response interceptors run after receiving (ideal for logging, metrics, error wrapping)
  • Supports chaining multiple interceptors

Design decisions:

  • Batch calls: interceptors run once per batch (transport-level), per-item errors in BatchElem.Error
  • Follows gRPC/Connect RPC interceptor patterns
  • Zero performance impact when not configured

Testing

  • Added 11 comprehensive tests covering all RPC methods
  • Tests verify interceptor chaining, error handling, and batch behavior
  • All tests passing

Breaking Changes

None - purely additive API

@fjl fjl closed this Nov 26, 2025
@samuelarogbonlo
Copy link
Contributor Author

@fjl Please kindly comment as to why this was closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ethclient support rpc custom handler

2 participants