Proxy HTTPS with HTTP in Node.js express -


i wrote express app http proxy, intercept , analyse of network traffic. parts of traffic app interested in http, still want app proxy https users can use without setting.

my express app created http server. when testing, changed proxy setting in chrome switchyomega, proxy https connections http. http works well, express app couldn't these proxy requests https.

so wrote simple tcp proxy check on them, , find they're this:

connect hostname:443 http/1.1 host: hostname proxy-connection: keep-alive user-agent: my_agent  encrypted https 

i believe these requests http, why express isn't receiving them?

for sure if change browser proxy setting ignore https, app works well. want know if there workaround can use proxy protocols http , 1 port.

thx.

update- code express app

app.use('*', function (req, res, next) {     // print request app receive     console.log('received:', req.url) })  app.use(bodyparser.text({type: '*/*'})) app.use(cookieparser()) app.use(logger('dev')) app.use(express.static(path.join(__dirname, 'public')))  // serve web pages app, request targeting server // handled here(right ip , port), proxy request gets handled after this. app.use('/', internalroute)  // analyse part want app.use('/end_point_i_want', myroute)  // handle proxy requests app.use('*', function (req, res, next) {   // proxy request here }) 

the problem is, first middleware, used display requests app receive, can't catch https proxy requests wrapped in http described above. , of course middleware used proxy can't catch them either.

update-tried node-http-prxoy, no luck

var httpproxy = require('http-proxy')   , http = require('http')   , fs = require('fs')  var options = {target: 'http://127.0.0.1:8099'}   , proxy = httpproxy.createserver(options)  http.createserver(function (req, res) {   console.log(req.url)   proxy.web(req, res) }).listen(5050) 

with above code, , browser setting proxy protocols http, works same express app. https proxy requests gets err_empty_response, , nothing on console.

with below options, seems have change proxy protocol https, i'd rather not use, @ least now. , err_proxy_certificate_invalid self-signed certs...

var options  = { secure: true                , target: 'http://127.0.0.1:8099'                , ssl: { key: fs.readfilesync('cert/key.pem', 'utf8')                       , cert: fs.readfilesync('cert/server.crt', 'utf8')                       }                } 

update- pin point problem 'connect' event listener

through searching, found this post helpful.

it pointed out http server doesn't have listener connect event. tried code in post, works. last comment of post mentioned, app serves proxy in order data, proxy request proxy in order go on greatfirewall.

the process : browser -> my_app -> another_proxy -> target.

without another_proxy, http proxy, works both http , https. failed chain them up. another_proxy use supports https on http.

it's hard see might wrong, since haven't posted code.

however, if want create simple proxy supports http , https, think should consider using module node-http-proxy.

their readme has example code common scenarios, , sounds support needs fine.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -