Open
Description
Hey,
So while I was testing some behaviour with proxy chaining with PAC files. I noticed that http requests weren't being handled correctly. The specific flow that I was trying was: request -> mockttp proxy -> PAC file -> 2nd mockttp proxy -> web server
.
Here's a script that shows the issue:
const mockttp = require("mockttp");
// start local server to host a pac file
const server = require("http").createServer((req, res) => {
console.log("Request made to PAC file server");
if (req.url === '/proxy.pac') {
console.log("PAC file server response");
res.writeHead(200, { 'Content-Type': 'text/javascript' });
res.write(`
function FindProxyForURL(url, host) {
return "PROXY localhost:8096";
}`);
}
res.end();
});
server.listen(5010, 'localhost', () => console.log("Started PAC file server on localhost:5010"));
// Launch proxies
(async () => {
const https = await mockttp.generateCACertificate();
// Proxy that uses PAC file
const proxy = mockttp.getLocal({ https });
await proxy.start(8095);
console.log('Started 1st Proxy on 8095');
await proxy.forAnyRequest().thenPassThrough({
beforeRequest: req => {
console.log('Reached the 1st Proxy:', req.url)
return req;
},
ignoreHostHttpsErrors: true,
proxyConfig: {
proxyUrl: 'pac+http://localhost:5010/proxy.pac'
}
});
// Proxy that handles requests from resolved PAC file
const proxy2 = mockttp.getLocal({ https });
await proxy2.start(8096);
console.log('Started 2nd Proxy on 8096');
await proxy2.forAnyRequest().thenPassThrough({
ignoreHostHttpsErrors: true,
beforeRequest: req => {
console.log('Reached the 2nd Proxy:', req.url)
return req;
}
});
})();
/**
* Failing Request: curl -k -x "http://127.0.0.1:8095/" "http://example.com/" -A "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0"
* Working Request: curl -k -x "http://127.0.0.1:8095/" "https://example.com/" -A "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0"
*/
Basically https
requests work as expected but http
request fail to connect. From the bit of testing I did, it seems to have something to do with how mockttp sets the request headers as a raw array when forwarding requests and perhaps the setDefaultHeaders
request option but I'm not entirely sure.
Metadata
Metadata
Assignees
Labels
No labels