The proxy server is running locally. From the client it receives http.request , which it transmits to a server on the network. From the server on the network, the proxy server receives the response, replaces the HTTP headers and then sends them to the client.
I write a proxy on Node.js. I can not get the title by the client. Node.js is optional - in any way possible.
Code edited
var http = require('http'); http.createServer(onRequest).listen(9000); function onRequest(req, res) { var options = { hostname: 'www.google.ru', port: 80, path: req.url }; var proxy = http.request(options, function(res) { res.on('end', function() { res.headers['Random-Header'] = 'Random-Content'; }); res.pipe(res, { end: true }); }); req.pipe(proxy, { end: true }); } Update
I tried to move the line http.createServer(onRequest).listen(9000); so that it was after the determination of onRequest , but nothing has changed.
onRequestdefined after the first use? - dzhioevres? You are trying to set the value of the wrong variable. An example . Secondly, the documentation indicatesresponse.setHeader(name, value)- perhaps the option via.headers[...]not correct. Thirdly, I don’t understand Node.js, I see..pipe(), but I still have doubts: does the client respond after.pipe()response from a remote server? - Regentfunction funcName(){}raised by the interpreter, the function declared in this way can be safely used in the code above its declaration. - NumminorihSFresponse.setHeaderyou got excited: you have the variablerescalled. By the way, the header must be set before sending the data. And you_res.on('end'it is installed at the very end (_res.on('end'). - Regentrescorrected..headers[...]replaced withresponse.setHeader. I write with Node.js for the first time, so I’m looking badly in the documentation and can’t find how.pipe()works in detail. I did not find yet a way to check whether the response is sent to the client only after the response from the remote server has arrived. If the proxy server is started with this code, then athttp://127.0.0.1:9000/Google opens in the browser, so I suspect that the routing still works correctly. - Aktash