Merge provider metadata with header metadata in RequestContext class #1428
+73
−6
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.
Merge Provider Configuration Metadata into Hook Context
Description
This PR implements metadata merging functionality in the
RequestContext.metadatagetter that allows hooks to access metadata defined in provider configurations (likeconf.json) by merging it with HTTP header metadata. The implementation maintains backward compatibility while unlocking powerful new capabilities for hook developers.Motivation
Previously, hooks could only access metadata passed via HTTP headers (
x-portkey-metadata), making configuration-based metadata completely inaccessible. This limitation prevented hooks from implementing:This change enables hooks to access rich metadata from provider configurations while maintaining the ability to override via HTTP headers, creating a flexible single source of truth for metadata.
Type of Change
How Has This Been Tested?
Test Details
Unit Tests Added (5 test cases):
Manual Testing:
Implementation Details
Core Changes
File:
src/handlers/services/requestContext.tsBefore:
After:
Architecture Flow
Merge Priority
Use Cases Unlocked
1. Regional Compliance Hook
2. Performance Tier Hook
3. Fallback Tracking Hook
Checklist
Related Issues
This addresses a limitation discovered during plugin development where configuration-based metadata was inaccessible to hooks, requiring unnecessary duplication of metadata in both configuration files and HTTP headers.
Additional Technical Details
Performance Characteristics
Security Considerations
Backward Compatibility
Reviewer Notes
Files Changed
src/handlers/services/requestContext.ts- Core implementation (metadata getter)tests/unit/src/handlers/services/requestContext.test.ts- New test cases