Commit a27d55a
authored
feat: Add CONNECT tunneling support for HTTP proxy in sandboxed environments (#791)
This PR is a follow-up of PR #788, which unfortunately didn't fully fix
the use of **apify-cli** in Claude Code sandbox (in the browser, not the
local one).
Currently, this is what's happening :
1. Proxy receives the request
2. Proxy returns: HTTP/1.1 301 Moved Permanently
3. Location: https://api.apify.com:443/v2/users/me (adds explicit :443
port)
4. axios follows redirect to https://api.apify.com:443/v2/users/me
5. Proxy strips the :443 and redirects back to
https://api.apify.com/v2/users/me
6. **Infinite loop!**
This is a known `axios` problem, referenced in several **unsolved**
issues :
- axios/axios#6725
- axios/axios#2072
- axios/axios#925
- axios/axios#4531
To fix this issue, this PR adds support for CONNECT tunneling through
HTTP/HTTPS proxies, using
[proxy-agents](https://github.com/TooTallNate/proxy-agents) modules.
What this does :
1. HttpsProxyAgent sends CONNECT api.apify.com:443
2. Proxy establishes tunnel (returns 200 OK)
3. Client does TLS handshake through tunnel
4. Encrypted traffic flows through tunnel
5. Proxy cannot see/modify the HTTPS traffic (acts like classic proxy)
6. **No redirects, no loops!**
~By precaution, we keep here the current http[s] agent implementation
when the `HTTP[S]_PROXY` env vars are not defined.~ (Changed since
commit 89571f9)1 parent a82832a commit a27d55a
3 files changed
+13
-29
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
| 1 | + | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
77 | | - | |
78 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
79 | 83 | | |
80 | 84 | | |
81 | 85 | | |
| |||
90 | 94 | | |
91 | 95 | | |
92 | 96 | | |
| 97 | + | |
| 98 | + | |
93 | 99 | | |
94 | 100 | | |
95 | 101 | | |
| |||
0 commit comments