apify / proxy-chain

Node.js implementation of a proxy server (think Squid) with support for SSL, authentication and upstream proxy chaining.
https://www.npmjs.com/package/proxy-chain
Apache License 2.0
804 stars 138 forks source link

intercept local requests #520

Closed korizyx closed 11 months ago

korizyx commented 11 months ago

I was trying to capture the request I'm making using the node itself, but it doesn't return me anything the proxy-chain event functions, follow the code below:

import ProxyChain from "proxy-chain";
import krop from "krop";

const server = new ProxyChain.Server({ port: 8001 });

server.listen(() => {
  console.log(`Proxy server is listening on port ${8001}`);
});

// Emitted when HTTP connection is closed
server.on("connectionClosed", ({ connectionId, stats }) => {
  console.log(`Connection ${connectionId} closed`);
  console.dir(stats);
});

// Emitted when HTTP request fails
server.on("requestFailed", ({ request, error }) => {
  console.log(`Request ${request.url} failed`);
  console.error(error);
});

await krop("www.google.com", {
  http2: true,
  proxy: "127.0.0.1:8001",
});
Tankonyako commented 11 months ago

Hello you can filter requests using prepareRequestFunction, req.url or hostname

korizyx commented 11 months ago

thx