You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When testing nodejs/node#57165 I noticed that there are some behavior differences between ProxyAgent and curl which may be interesting. Most notably, ProxyAgent always tunnels with CONNECT even for pure HTTP traffic.
Reproducible By
Create a proxy server, like this:
// server.js'use strict';consthttp=require('http');constnet=require('net');functionlog(req){console.log('----- Received Request -----');console.log(`${req.method}${req.url} HTTP/${req.httpVersion}`);for(constheaderinreq.headers){console.log(`${header}: ${req.headers[header]}`);}}constserver=http.createServer((req,res)=>{log(req);const[hostname,port]=req.headers.host.split(':');consttargetPort=port||80;constoptions={hostname: hostname,port: targetPort,path: req.url,method: req.method,headers: req.headers};constproxyReq=http.request(options,proxyRes=>{res.writeHead(proxyRes.statusCode,proxyRes.headers);proxyRes.pipe(res,{end: true});});proxyReq.on('error',err=>{console.error('Proxy request error: '+err.message);res.writeHead(500);res.end('Proxy error: '+err.message);});req.pipe(proxyReq,{end: true});});server.on('connect',function(req,clientSocket,head){log(req);const[hostname,port]=req.url.split(':');constserverSocket=net.connect(port,hostname,()=>{clientSocket.write('HTTP/1.1 200 Connection Established\r\n'+'Proxy-agent: Node.js-Proxy\r\n'+'\r\n');serverSocket.write(head);clientSocket.pipe(serverSocket);serverSocket.pipe(clientSocket);});serverSocket.on('error',(err)=>{console.error('Error on CONNECT tunnel:',err.message);clientSocket.write('HTTP/1.1 500 Connection Error\r\n\r\n');clientSocket.end();});});server.listen(8000,'127.0.0.1',()=>{const{ address, port }=server.address();console.log(`Proxy server listening on http://${address}:${port}`);});
And send a request to http://example.com like this:
Output from client with undici ProxyAgent (change the http://example.com to https://example.com in the snippet above)
CONNECT example.com:80 HTTP/1.1
host: example.com
connection: close
Environment
macOS though I am sure this is irrelevant.
Additional context
I am not sure this really counts as a bug or not. But from my impression, not all proxy servers in the wild supports tunneling on non-443 ports. It may be safer to follow what curl does, because the setup of proxy server and target servers are not always in the control of users. If they end up having to work with a proxy server that does not support tunnelling on non-443 ports, and also having to connect to a server on 80 port or others with the proxy, there would be no way for them to work around it.
The text was updated successfully, but these errors were encountered:
I agree we should follow what curl is doing, but... I'm not sure how impactful this is, as we shouldn't really encourage anyone to pass through a proxy with plain HTTP.
I'm not sure how impactful this is, as we shouldn't really encourage anyone to pass through a proxy with plain HTTP.
Agreed though I think from user's perspective, how the proxy or the endpoint works isn't usually in their control, so this might come up at some point for people who have to deal with this set up..the adoption of HTTPS vary greatly depending on which part of the world you are in (e.g. see https://www.ndss-symposium.org/wp-content/uploads/madweb25-1.pdf).
Anyway, I don't think it's urgent, just that it would be safer if we are aligned with curl eventually.
Bug Description
When testing nodejs/node#57165 I noticed that there are some behavior differences between ProxyAgent and curl which may be interesting. Most notably, ProxyAgent always tunnels with CONNECT even for pure HTTP traffic.
Reproducible By
Create a proxy server, like this:
And send a request to
http://example.com
like this:Expected Behavior
If I run
curl -x http://127.0.0.1:8000 http://example.com
, this is the output from the proxy server:Logs & Screenshots
Using the client with undici, the proxy server always get a CONNECT:
This is somewhat similar to the one I get for sending requests to
https://example.com
using curl - which does use CONNECT.Output from
curl -x http://127.0.0.1:8000 https://example.com
Output from client with undici ProxyAgent (change the
http://example.com
tohttps://example.com
in the snippet above)Environment
macOS though I am sure this is irrelevant.
Additional context
I am not sure this really counts as a bug or not. But from my impression, not all proxy servers in the wild supports tunneling on non-443 ports. It may be safer to follow what curl does, because the setup of proxy server and target servers are not always in the control of users. If they end up having to work with a proxy server that does not support tunnelling on non-443 ports, and also having to connect to a server on 80 port or others with the proxy, there would be no way for them to work around it.
The text was updated successfully, but these errors were encountered: