feat: HTTP trailers support infrastructure #429
Draft
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
Implements comprehensive HTTP trailers support for
@fastify/reply-from
, enabling automatic forwarding of HTTP trailers from upstream servers to clients across all supported HTTP protocols.Key Features
🏗️ Core Infrastructure
⚙️ Configuration Options
forwardTrailers
- Enable/disable trailer forwarding (default: true)stripForbiddenTrailers
- Remove forbidden trailer fields (default: true)requireTrailerSupport
- Only forward when client advertises support (default: false)trailersTimeout
- Timeout for trailer collection (default: 5s)maxTrailerSize
- Size limit for trailer data (default: 8KB)🎯 Request/Response Hooks
rewriteTrailers(trailers, request)
- Transform upstream trailers before forwardingonTrailers(request, reply, trailers)
- Custom trailer handling logicaddTrailers
- Add custom trailers (static values or async functions)Implementation Details
Automatic Trailer Forwarding: Trailers from upstream servers are automatically collected and forwarded to clients while respecting RFC specifications and security requirements.
Security & Performance:
Multi-Protocol Support: Works seamlessly across HTTP/1.1, HTTP/2, and Undici clients with protocol-specific optimizations.
Usage Examples
Test Coverage
Backward Compatibility
Fully backward compatible - all trailer functionality is opt-in and defaults to enabled for seamless adoption.
Related
Implements the comprehensive plan outlined in
TRAILERS.md