Skip to content

Barslev/ana 490 fix http proxy handling in npm cli for https requests#732

Merged
jdalton merged 3 commits intomainfrom
barslev/ana-490-fix-http-proxy-handling-in-npm-cli-for-https-requests
Sep 11, 2025
Merged

Barslev/ana 490 fix http proxy handling in npm cli for https requests#732
jdalton merged 3 commits intomainfrom
barslev/ana-490-fix-http-proxy-handling-in-npm-cli-for-https-requests

Conversation

@barslev
Copy link
Contributor

@barslev barslev commented Sep 11, 2025

No description provided.

@barslev barslev requested a review from jdalton September 11, 2025 11:14
@claude
Copy link

claude bot commented Sep 11, 2025

Claude finished @barslev's task —— View job


PR Review: HTTP Proxy Handling Fix ✅

Review Progress:

  • Read repository guidelines (CLAUDE.md)
  • Analyze changed files
  • Review code quality and best practices
  • Check for potential bugs and security issues
  • Evaluate performance considerations
  • Assess architecture decisions
  • Provide actionable feedback

Summary

This PR fixes HTTP proxy handling for HTTPS requests and ensures proxy configuration is consistently passed to the Coana integration. The changes are well-implemented and address a clear bug in proxy agent selection.

🔍 Detailed Review

Fixed Critical Bug in src/utils/sdk.mts:117

- const ProxyAgent = apiProxy?.startsWith('http:')
+ const ProxyAgent = apiBaseUrl?.startsWith('http:')

Excellent fix! This was checking the wrong variable. The proxy agent type should be determined by the API base URL's protocol, not the proxy URL's protocol. This ensures:

  • HttpProxyAgent for HTTP API endpoints
  • HttpsProxyAgent for HTTPS API endpoints (default)

Improved Coana Integration in src/utils/coana.mts

The addition of proxy configuration to the Coana spawn function is well-implemented:

const proxyUrl = getDefaultProxyUrl()
if (proxyUrl) {
  mixinsEnv['SOCKET_CLI_API_PROXY'] = proxyUrl
}
  • Follows existing patterns consistently
  • Proper conditional logic
  • Maintains environment variable consistency

Clean API Design in src/utils/sdk.mts

Making getDefaultProxyUrl() exportable is the right approach:

- function getDefaultProxyUrl(): string | undefined {
+ export function getDefaultProxyUrl(): string | undefined {
  • Enables code reuse without duplication
  • Maintains single source of truth for proxy configuration

🎯 Architecture & Best Practices

Strengths:

  1. Consistent patterns: Uses same conditional logic as other environment variable handling
  2. Proper separation: Proxy configuration logic stays centralized in sdk.mts
  3. Type safety: Maintains proper TypeScript types throughout
  4. Environment variable naming: Follows established SOCKET_CLI_API_PROXY convention

Code Quality:

  • Clean, readable changes
  • Follows repository conventions (2-space indentation, camelCase, etc.)
  • Proper import organization
  • No commented-out code or debug statements

🔒 Security & Performance

Security:

  • ✅ No secrets or sensitive data exposed
  • ✅ URL validation already exists via isUrl() function
  • ✅ Proxy handling follows established security patterns

Performance:

  • ✅ Minimal overhead - only adds proxy env var when needed
  • ✅ No unnecessary computations or allocations
  • ✅ Efficient environment variable handling

🧪 Testing Considerations

The changes affect critical networking functionality. Consider adding tests for:

  • Proxy agent selection logic (HTTP vs HTTPS)
  • Coana proxy environment variable passing
  • Integration between proxy configuration sources

📋 Final Assessment

Overall: Excellent implementation ⭐

This PR demonstrates:

  • Clear understanding of the proxy handling issue
  • Proper debugging and root cause analysis
  • Clean, maintainable solution
  • Consistent with codebase patterns
  • No breaking changes to existing API

The bug fix in sdk.mts:117 was critical - using apiProxy instead of apiBaseUrl would have caused incorrect proxy agent selection for HTTPS endpoints.


Copy link
Contributor

@jdalton jdalton left a comment

Choose a reason for hiding this comment

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

Thank you @barslev !

@jdalton jdalton merged commit 21c7e62 into main Sep 11, 2025
21 checks passed
@jdalton jdalton deleted the barslev/ana-490-fix-http-proxy-handling-in-npm-cli-for-https-requests branch September 11, 2025 11:50
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