Skip to content

feat: Add proxy environment support#11

Closed
luisAzcuaga wants to merge 12 commits intoepignosisx:mainfrom
luisAzcuaga:feat/proxy-support
Closed

feat: Add proxy environment support#11
luisAzcuaga wants to merge 12 commits intoepignosisx:mainfrom
luisAzcuaga:feat/proxy-support

Conversation

@luisAzcuaga
Copy link
Copy Markdown

@luisAzcuaga luisAzcuaga commented Sep 17, 2025

🎯 Problem

VCR-JS failed in corporate proxy environments with "socket hang up" errors when applications used HTTP CONNECT requests to establish proxy tunnels. This prevented testing in many enterprise
environments.

✅ Solution

Added comprehensive proxy support:

  • CONNECT request detection: Automatically detects and passes through CONNECT requests for proxy tunnel establishment
  • Simplified proxy handling: Ensures deterministic tests by allowing API requests through tunnels to be recorded/replayed normally
  • Corporate environment compatibility: Works seamlessly with proxy authentication and tunneling
  • Clean operation: Removed debug logging for production-ready silent operation

🧪 Testing

  • ✅ All existing tests pass
  • ✅ New proxy tunnel scenarios tested successfully
  • ✅ Deterministic test results with consistent authentication tokens
  • ✅ Works in corporate environments with proxy authentication

📦 Dependencies

  • Upgraded to enhanced @mswjs/interceptors fork with CONNECT method support
  • Maintains backward compatibility with existing cassettes

🚀 Impact

  • Enables VCR testing in corporate proxy environments
  • Maintains all existing functionality
  • Provides reliable, deterministic test results
  • Ready for production use

Footnote:

The changes done with this PR and the changes done here luisAzcuaga/interceptors#2 were required to solve the issue mentioned here #3

luisAzcuaga and others added 12 commits September 15, 2025 12:45
Updates httpbin.org test recordings with current timestamps, trace IDs, and IP addresses.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Handles HTTP CONNECT requests by responding with 200 Connection Established
status, preventing proxy requests from reaching real proxy servers and
avoiding 503 errors in corporate proxy environments.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Let CONNECT requests pass through to actual proxy instead of intercepting
- Remove intercepted 200 response that was breaking tunnel establishment
- Add comprehensive debug logging for proxy requests and VCR decisions
- Fixes tunneling socket errors in corporate proxy environments

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Fix playback mode to not record responses for replayed requests
- Add tracking of playback requests to prevent double recording
- Enhance proxy detection with header-based detection (proxy-authorization, proxy-connection)
- Use request.passthrough() for better interceptor cleanup on proxy requests
- Resolves response recording conflicts in playback mode

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Track CONNECT request targets in proxyTunnels set
- Detect when requests are going to established proxy tunnel hosts
- Pass through all requests to proxy tunnel hosts without interference
- Fix request.passthrough() method calls to use correct API
- Refresh test cassettes with current recordings

This resolves socket hang up errors in corporate proxy environments
by ensuring all proxy-related traffic passes through without VCR
intervention after the initial CONNECT tunnel is established.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Replace request.passthrough() with simple return for CONNECT requests
- Fixes "request.passthrough is not a function" errors
- Ensures proper proxy tunnel establishment in corporate environments
- Tests now pass successfully with proxy tunnel tracking

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Remove noisy debug console.log statements for cleaner test output
- Add proxy tunnel detection in response handler to prevent recording
- Ensure proxy tunnel requests are completely bypassed by VCR

This prevents proxy requests from being recorded/interfered with
while maintaining clean test output without debug noise.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Remove proxy tunnel tracking that bypassed all requests to target hosts
- Only pass through CONNECT requests needed for tunnel establishment
- Allow API requests through tunnels to be recorded/replayed normally
- Ensures consistent test results with proper cassette playback

This fixes the issue where tests were getting different tokens each
run because API requests were bypassing VCR recording/playback.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Clean up console.log statements throughout cassette.ts
- Provides cleaner test output without debug noise
- VCR functionality remains unchanged, just silent operation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Use luisAzcuaga/interceptors#main for CONNECT method support
- Enables proxy tunnel handling in corporate environments
- Provides built distribution files for direct GitHub installation
- Maintains cassette compatibility with existing implementations

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

1 participant