feat: support "CONNECT", socket-based interception#2
Merged
luisAzcuaga merged 60 commits intomainfrom Sep 17, 2025
Merged
Conversation
…js#397) Co-authored-by: avivasyuta <avivasyuta@avito.ru> Co-authored-by: Artem Zakharchenko <kettanaito@gmail.com>
Co-authored-by: avivasyuta <avivasyuta@avito.ru> Co-authored-by: Artem Zakharchenko <kettanaito@gmail.com>
Co-authored-by: Antonio Cheong <acheong@student.dalat.org> Co-authored-by: Artem Zakharchenko <kettanaito@gmail.com> Co-authored-by: Aleksey Ivasyuta <avivasyuta@gmail.com> Co-authored-by: avivasyuta <avivasyuta@avito.ru>
…th a mocked response (mswjs#432)
mswjs#453) Co-authored-by: Artem Zakharchenko <kettanaito@gmail.com>
Co-authored-by: Artem Zakharchenko <kettanaito@gmail.com>
Clean up verbose debug logging that was added for CONNECT method debugging. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Proxy agents like tunnel-agent and hpagent may not implement the standard destroy() method, causing TypeError when the interceptor attempts cleanup. Added proper type checking before calling agent.destroy() to prevent crashes with CONNECT tunneling requests. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
44534e5 to
00ed0a1
Compare
This was referenced Sep 17, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Continuing the work of on the PR mswjs#483 I've done this fully functional.
Summary
This PR adds comprehensive support for the HTTP CONNECT method in the interceptors library, enabling proper handling of proxy tunneling scenarios. The implementation includes socket-based
interception capabilities and fixes a critical issue with proxy agent cleanup that was causing runtime errors.
Changes
🚀 Features
- Added support for the CONNECT HTTP method in the interceptor
- Enables handling of proxy tunnel establishment requests
- Implemented socket-based interception mechanism
- Allows intercepting and handling CONNECT tunnel requests at the socket level
- Added Duplex socket handling for tunnel communication
- Included compiled TypeScript files in the repository
- Enables direct installation from GitHub without requiring a build step
- Supports development workflows that depend on GitHub references
🐛 Bug Fixes
- Critical Fix: Added safe destroy check for proxy agents in the terminate() method
- Problem: Proxy agents (like tunnel-agent, hpagent) don't implement the standard destroy() method, causing TypeError: _a.destroy is not a function
- Solution: Added proper type checking before calling agent.destroy() to prevent crashes with CONNECT tunneling requests
- Impact: Eliminates runtime errors when using VCR libraries or other tools that intercept proxy requests
🔧 Maintenance
- Added debugging support for CONNECT method during development
- Removed debug logging from production code
Test Coverage
Breaking Changes
None. All changes are backward compatible.
Use Cases
This PR enables the interceptors library to properly handle:
Example Usage
interceptor.on('request', ({ request }) => {
// Handle CONNECT requests for proxy tunneling
if (request.method === 'CONNECT') {
return request.respondWith(
new Response(null, {
status: 200,
statusText: 'Connection Established',
})
);
}
});
Impact
This implementation makes the interceptors library more robust and suitable for enterprise environments where proxy infrastructure is common.
🤖 Generated with Claude Code