refactor: extract validateAuthHeaderEnv and isValidHeaderName helpers#4783
Conversation
Centralizes HTTP header name validation into proxy-utils.js: - validateAuthHeaderEnv(): throw-on-invalid pattern (anthropic, openai) - isValidHeaderName(): boolean predicate (copilot-byok loop) Fixes #4709 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
✅ Coverage Check PassedOverall Coverage
📁 Per-file Coverage Changes (1 files)
Coverage comparison generated by |
There was a problem hiding this comment.
Pull request overview
This PR refactors repeated HTTP header-name validation logic used by api-proxy provider adapters into shared helpers in containers/api-proxy/proxy-utils.js, addressing #4709 and reducing duplicated validation/try-catch patterns across providers.
Changes:
- Added
validateAuthHeaderEnv(envVarName, rawValue, defaultHeader)to centralize trimming + header-name validation + consistent error messages for custom auth-header env vars. - Added
isValidHeaderName(name)as a boolean wrapper around Node’shttp.validateHeaderName()to simplify skip-on-invalid header handling. - Updated Anthropic/OpenAI adapters and the Copilot BYOK extra-header parser to use the new helpers instead of local duplicated logic.
Show a summary per file
| File | Description |
|---|---|
| containers/api-proxy/proxy-utils.js | Introduces shared header-name validation helpers and exports them for adapter use. |
| containers/api-proxy/providers/openai.js | Replaces inline env-var header validation IIFE with validateAuthHeaderEnv. |
| containers/api-proxy/providers/anthropic.js | Replaces inline auth-header env-var validation with validateAuthHeaderEnv (defaulting to x-api-key). |
| containers/api-proxy/providers/copilot-byok.js | Replaces per-header try/catch validation with isValidHeaderName for skip-on-invalid behavior. |
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
|
Smoke Test: Copilot PAT Auth — PR #4783 by @lpcox
PR: refactor: extract validateAuthHeaderEnv and isValidHeaderName helpers
|
🔍 Smoke Test: API Proxy OpenTelemetry Tracing
All completed scenarios pass. S5 will populate once the workflow finishes.
|
|
perf(doc-maintainer): reduce per-run token usage Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "registry.npmjs.org"See Network Configuration for more information.
|
🔥 Smoke Test ResultsPR: refactor: extract validateAuthHeaderEnv and isValidHeaderName helpers
Overall: PASS
|
🔍 Chroot Version Comparison Results
Overall: ❌ FAILED — Python and Node.js versions differ between host and chroot environments.
|
|
refactor: extract validateAuthHeaderEnv and isValidHeaderName helpers
Running in direct BYOK mode (AWF_AUTH_TYPE=github-oidc + AWF_AUTH_AZURE_* + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry, o4-mini-aw) authenticated via Microsoft Entra Overall: FAIL cc @lpcox
|
|
refactor: extract validateAuthHeaderEnv and isValidHeaderName helpers
|
|
GitHub API: ✅ PASS Total: PASS
|
Smoke Test: Copilot BYOK (Direct) Mode ✅ PASSTest Results:
Mode: Direct BYOK (COPILOT_PROVIDER_API_KEY via api-proxy sidecar)
|
Smoke Test: GitHub Actions Services Connectivity
Overall: FAIL —
|
Summary
Centralizes the repeated HTTP header name validation pattern into two helpers in
proxy-utils.js:validateAuthHeaderEnv(envVarName, rawValue, defaultHeader)— reads/trims/validates an env var as an HTTP header name, throwing with a descriptive error on failure. Replaces the throw-on-invalid IIFEs in anthropic.js and openai.js.isValidHeaderName(name)— boolean predicate wrappinghttp.validateHeaderName(). Replaces the try/catch in copilot-byok.js's header loop.Fixes #4709