Refactor api-proxy request pipeline into focused modules#3876
Open
Copilot wants to merge 3 commits into
Open
Conversation
Copilot
AI
changed the title
[WIP] Refactor proxy-request.js into focused modules
Refactor api-proxy request pipeline into focused modules
May 26, 2026
Contributor
✅ Coverage Check PassedOverall Coverage
📁 Per-file Coverage Changes (1 files)
Coverage comparison generated by |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the API proxy request pipeline by extracting billing parsing, deprecated header tracking, and upstream response handling into focused modules while preserving the existing proxy request surface.
Changes:
- Added focused modules for billing headers, deprecated-header learning/stripping, and upstream response orchestration.
- Rewired
proxy-request.jsto import those modules and keep existing exports intact. - Preserved the existing test-facing reset and billing helper re-export paths.
Show a summary per file
| File | Description |
|---|---|
containers/api-proxy/proxy-request.js |
Replaces inlined helper implementations with module imports and wires the response handler factory. |
containers/api-proxy/upstream-response.js |
Adds extracted upstream response logging, retry, streaming, token tracking, and completion handling. |
containers/api-proxy/deprecated-header-tracker.js |
Adds extracted module-level deprecated header cache and learn/strip helpers. |
containers/api-proxy/billing-headers.js |
Adds extracted billing/quota header parsing utility. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 4/4 changed files
- Comments generated: 0
This was referenced May 26, 2026
The api-proxy container crashes with 'Cannot find module ./deprecated-header-tracker' because the file was not included in the Dockerfile COPY instruction. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
containers/api-proxy/proxy-request.jshad grown into a multi-responsibility module (~764 LOC) combining deprecated-header learning, billing parsing, upstream response orchestration, and core proxy transport. This PR extracts those cohesive concerns into dedicated modules while preserving call sites and runtime behavior.Module split: deprecated header learning
containers/api-proxy/deprecated-header-tracker.js.getDeprecatedValuesForHeadermaybeStripLearnedHeaderValuesparseDeprecatedHeaderFromBodylearnAndStripDeprecatedHeaderValueresetDeprecatedHeaderValuesForTestsand wired existing test reset export to it.Module split: billing header parsing
containers/api-proxy/billing-headers.js.extractBillingHeadersinto a dedicated utility module.proxy-request.js/server.jsusage.Module split: upstream response handling
containers/api-proxy/upstream-response.js.handleUpstreamResponselogUpstreamAuthErrorlogRequestCompletioncreateUpstreamResponseHandlers(...)to inject existing dependencies without behavior drift.proxy-request.jstrimmed to transport orchestrationproxyRequest,sendUpstreamRequest,buildRequestHeaders, and existing external exports/call paths intact.