Skip to content

Feat/support connect method#1

Merged
luisAzcuaga merged 0 commit into
mainfrom
feat/support-connect-method
Sep 17, 2025
Merged

Feat/support connect method#1
luisAzcuaga merged 0 commit into
mainfrom
feat/support-connect-method

Conversation

@luisAzcuaga

@luisAzcuaga luisAzcuaga commented Sep 17, 2025

Copy link
Copy Markdown
Owner

Summary

Retaking the work done on the PR mswjs#483 I've continued the work in other to make it function.

This PR completes HTTP CONNECT method support for proxy scenarios, enabling the interceptors library to properly handle HTTP tunneling
requests used by proxy agents like hpagent.

Key Improvements

  • ✅ Fixed empty URL handling - CONNECT requests with empty URLs (common pattern) now work correctly
  • ✅ Fixed CONNECT path handling - For CONNECT requests, the path option contains the target host rather than a URL path
  • ✅ Enhanced proxy test coverage - Added comprehensive tests for real-world proxy scenarios
  • ✅ Added debugging support - Comprehensive logging for troubleshooting proxy flows

Changes Made

Core Fixes

  1. normalizeClientRequestArgs.ts - Handle empty URL strings for CONNECT requests
  2. getUrlByRequestOptions.ts - Proper path handling for CONNECT method (target host vs URL path)
  3. got-hpagent-proxy.test.ts - Complete proxy flow test with tunneled requests

Enhanced Debugging

  1. NodeClientRequest.ts - Added detailed logging for CONNECT request lifecycle
  2. createRequest.ts - Added logging for request construction details

Test Results

Both CONNECT-related tests now pass:

  • test/modules/http/compliance/http-connect.test.ts - Basic CONNECT functionality
  • test/third-party/got-hpagent-proxy.test.ts - Real-world proxy agent integration

Proxy Flow Support

The library now properly supports the complete proxy flow:

  1. CONNECT Request → Establishes tunnel to target through proxy
  2. Tunnel Establishment → Receives 200 Connection Established response
  3. HTTP over Tunnel → Subsequent requests are intercepted and can be mocked

Real-World Impact

This enables libraries like vcr-js to properly intercept and mock proxy-based HTTP requests, which is crucial for testing
applications that use corporate proxies or HTTP tunneling.

Debugging

Added comprehensive logging that can be enabled with:

DEBUG=interceptors* your-command

Shows detailed information about:
- CONNECT request creation and URL construction
- Proxy authentication headers
- Response handling and tunnel establishment
- Error scenarios with detailed context

Test plan

- Run existing unit tests - all pass
- Run CONNECT-specific integration tests - both pass
- Test with real proxy scenario (got + hpagent) - works correctly
- Verify backward compatibility - no regressions
- Test logging output - comprehensive debugging available

🤖 Generated with https://claude.ai/code

@luisAzcuaga luisAzcuaga self-assigned this Sep 17, 2025
@luisAzcuaga luisAzcuaga merged commit 00ed0a1 into main Sep 17, 2025
@luisAzcuaga luisAzcuaga deleted the feat/support-connect-method branch September 17, 2025 21:46
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