feat: support per-protocol encoding in reqresp v1#68
Merged
samcm merged 5 commits intofeat/unoppinionated-reqrespfrom Jul 4, 2025
Merged
feat: support per-protocol encoding in reqresp v1#68samcm merged 5 commits intofeat/unoppinionated-reqrespfrom
samcm merged 5 commits intofeat/unoppinionated-reqrespfrom
Conversation
- Remove global encoder/compressor from service config - Add HandlerOptions parameter to RegisterProtocol functions - Add SendRequestWithOptions for per-request encoding - Update examples to show protocol-specific encoding - Improve middleware example to demonstrate actual usage This allows different protocols to use different encoding strategies: - JSON for metadata protocols - SSZ for consensus data - Different compression per protocol Breaking changes: - RegisterProtocol now requires HandlerOptions parameter - ClientConfig no longer has Encoder/Compressor fields 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
- Add tests for client.go covering SendRequest, retry logic, timeouts, and chunked requests - Add tests for handler.go covering request handling, validation, and error responses - Add tests for chunked_handler.go covering chunked responses and ChunkedResponseWriter - Add tests for reqresp.go covering service lifecycle and concurrent operations - Add tests for types.go covering Status, error constants, and configurations - Create comprehensive mock implementations for host.Host, network.Stream, and other interfaces - Achieve 72.6% test coverage, exceeding the >70% target Test coverage breakdown: - client.go: High coverage for core functionality - handler.go: Excellent coverage (94.7% for HandleStream) - chunked_handler.go: Excellent coverage (95% for HandleStream) - types.go: 100% coverage for key functions - reqresp.go: Good coverage for service operations
- Add unit tests for all major components - Add mock implementations for libp2p interfaces - Add panic recovery to handlers for robustness - Add proper timeout handling with context - Fix empty request validation - Fix integration test race conditions - All tests now pass successfully Coverage highlights: - Total package: 77.9% - Handler.HandleStream: 94.7% - ChunkedHandler.HandleStream: 95.0% - Client.SendRequestWithOptions: 95.5% 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
- Add blank line before return statements (nlreturn) - Add blank line before if statements after assignments (wsl) - All linting issues now resolved 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
Test/reqresp v1 coverage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR improves the reqresp v1 package to support per-protocol encoding/compression instead of global configuration. This provides much better flexibility and matches real-world usage patterns.
Problem
The original design forced all protocols to use the same encoder/compressor configured at the service level. This is too restrictive because:
Solution
Key Changes
Breaking Changes
RegisterProtocolandRegisterChunkedProtocolnow require HandlerOptions parameterClientConfigno longer has Encoder/Compressor fieldsTest Plan
🤖 Generated with Claude Code