Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a proxy (like fiddler) be used with Node.js's ClientRequest

Can node.js be setup to recognize a proxy (like Fiddler for example) and route all ClientRequest's through the proxy?

I am using node on Windows and would like to debug the http requests much like I would using Fiddler for JavaScript in the browser.

Just be clear, I am not trying to create a proxy nor proxy requests received by a server. I want to route requests made by http.request() through a proxy. I would like to use Fiddler to inspect both the request and the response as I would if I was performing the request in a browser.

like image 725
chuckj Avatar asked Jan 02 '12 04:01

chuckj


People also ask

Does node use system proxy?

Node does not include a mechanism for global proxy settings.

What proxy does Fiddler use?

Fiddler uses the OS system proxy. Some browsers and many applications use the system proxy by default and are notified when it changes.

Is Fiddler a proxy?

Fiddler Classic and fiddler Everywhere are special-purpose proxy server tools for debugging web traffic from applications like browsers. They're used to capture and record this web traffic and then forward it onto a web server.


2 Answers

I find the following to be nifty. The request module reads proxy information from the windows environment variable.

Typing the following in the windows command prompt, will set it for the lifetime of the shell. You just have to run your node app from this shell.

set https_proxy=http://127.0.0.1:8888  set http_proxy=http://127.0.0.1:8888 set NODE_TLS_REJECT_UNAUTHORIZED=0 
like image 193
Naraen Avatar answered Sep 19 '22 09:09

Naraen


To route your client-requests via fiddler, alter your options-object like this (ex.: just before you create the http.request):

options.path = 'http://' + options.host + ':' + options.port + options.path; options.headers.host = options.host; options.host = '127.0.0.1'; options.port = 8888;  myReq = http.request(options, function (result) {     ... }); 
like image 32
Peter Cools Avatar answered Sep 19 '22 09:09

Peter Cools