Skip to content

Add undici-based HTTP/HTTPS proxy support with tests and documentation - #39

Open
rattalur wants to merge 13 commits into
codacy:mainfrom
rattalur:main
Open

Add undici-based HTTP/HTTPS proxy support with tests and documentation#39
rattalur wants to merge 13 commits into
codacy:mainfrom
rattalur:main

Conversation

@rattalur

@rattalur rattalur commented Sep 3, 2026

Copy link
Copy Markdown

This pull request adds support for running the CLI behind an HTTP or HTTPS proxy, configurable via standard environment variables. It introduces a new utility for proxy configuration, updates documentation to describe proxy usage, and adds direct support for proxying all API requests. The implementation ensures that proxy settings are respected consistently, including bypass logic via NO_PROXY, and is fully tested.

Proxy support implementation:

  • Added a new utility (src/utils/proxy.ts) that resolves HTTP_PROXY/HTTPS_PROXY (case-insensitive), honors NO_PROXY for bypassing, and installs an undici.ProxyAgent as the global dispatcher for all outbound API requests.
  • Updated the CLI entrypoint (src/index.ts) to call configureProxyFromEnv() before any API configuration or command registration, ensuring proxy settings are applied globally. [1] [2]

Dependencies and testing:

  • Added undici as a direct dependency in package.json to provide the proxy agent and dispatcher.
  • Added comprehensive unit tests for proxy resolution, bypass logic, and dispatcher installation in src/utils/proxy.test.ts.

Documentation updates:

  • Documented proxy support and environment variables in README.md (new "Proxy Support" section), AGENTS.md (environment variable table), and SPECS/README.md (feature changelog). [1] [2] [3] [4]

Resolves Issue #40

Copilot AI and others added 4 commits September 3, 2026 06:58
Co-authored-by: rattalur <145406381+rattalur@users.noreply.github.com>
Co-authored-by: rattalur <145406381+rattalur@users.noreply.github.com>
Add HTTP/HTTPS proxy support via undici ProxyAgent
@codacy-production

codacy-production Bot commented Sep 3, 2026

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 1 minor

Alerts:
⚠ 1 issue (≤ 0 issues of at least minor severity)

Results:
1 new issue

Category Results
Comprehensibility 1 minor

View in Codacy

🟢 Metrics 40 complexity · 0 duplication

Metric Results
Complexity 40
Duplication 0

View in Codacy

AI Reviewer: first review requested successfully. AI can make mistakes. Always validate suggestions.

Run reviewer

TIP This summary will be updated as you push new changes.

@codacy-production codacy-production Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

The implementation correctly introduces proxy support using undici, and the project remains 'up to standards' according to Codacy. However, there is a logic flaw that should be addressed before merging: the current configuration only checks the NO_PROXY bypass for the primary Codacy API host during initialization.

Because the undici.ProxyAgent is not initialized with the noProxy configuration, all other outbound requests (such as fetching CVE data from Mitre) will be forced through the proxy even if they are explicitly listed in the environment variables. Leveraging the library's native bypass support will provide a more robust and standard-compliant implementation.

About this PR

  • The implementation should aim for full parity with standard networking tools by ensuring all outbound requests—not just the primary API calls—respect the NO_PROXY configuration. Transitioning to the native noProxy option in undici will solve this systemically.

Test suggestions

  • Verify resolveProxyUrl handles precedence (HTTPS > HTTP) and case-insensitivity correctly.
  • Verify shouldBypassProxy handles exact matches, suffix matches, and the wildcard '*' correctly.
  • Verify configureProxyFromEnv installs the global dispatcher with the resolved URL.
  • Verify configureProxyFromEnv skips installation if the API host matches a NO_PROXY entry.
  • Verify proxy bypass logic respects the custom hostname from CODACY_API_BASE_URL.

TIP How was this review? Give us feedback

Comment thread src/utils/proxy.ts
Comment thread src/utils/proxy.ts
Copilot AI and others added 9 commits September 3, 2026 07:19
Co-authored-by: rattalur <145406381+rattalur@users.noreply.github.com>
Fix `npm run build` failing with missing `api/client` module errors
Co-authored-by: rattalur <145406381+rattalur@users.noreply.github.com>
Document NODE_EXTRA_CA_CERTS for TLS-intercepting corporate proxies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants