You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need to prevent a request from being sent to the target server, instead I would like to send it (unchanged, including all data) to another server and return the data from that server.
So the above CURL command should, for example, send/return data to/from 'https://127.0.0.1:443' instead of 'https://httpbin.org/anything'. Is it possible to do it with 'http-mitm-proxy'? My current code is as follows:
constProxy=require('http-mitm-proxy');constproxy=Proxy();proxy.onError((ctx,err)=>{console.error('Proxy error: ',err);});asyncfunctionsendAndGetData(ctx,host){// !!!!! Todo !!!!!: Ideally, just passing the request to `host` without reconstructing it. Maybe via connect?}asyncfunctiongetResponse(ctx){// Get proxy headersconstsym=Object.getOwnPropertySymbols(ctx.connectRequest).find(function(s){returnString(s)==='Symbol(kHeaders)';});console.log('Proxy headers: ',ctx.connectRequest[sym]);// Modify request headers// Add Proxy-Authorization header to request headersctx.proxyToServerRequestOptions.headers['Proxy-Authorization']=ctx.connectRequest[sym]['proxy-authorization'];// !!!!! Todo !!!!!: Here I want to send a request to https://127.0.0.1:443 and return a response from itreturnawaitsendAndGetData(ctx,'https://127.0.0.1:443');}proxy.onConnect(async(req,socket,head,callback)=>{// Hack: Add proxy headers to ctx. Without this ctx does not include proxy headersreq.headers;returncallback();});proxy.onRequest(async(ctx,callback)=>{// Get request headersconsole.log('Request headers: ',ctx.clientToProxyRequest.headers);// Intercepting proxy// No callback() so proxy request is not sent to the serverctx.proxyToClientResponse.end(awaitgetResponse(ctx));// MITM proxy// return callback();});proxy.listen({port: 8081});
Thank you in advance for any help.
The text was updated successfully, but these errors were encountered:
Hi,
I need to prevent a request from being sent to the target server, instead I would like to send it (unchanged, including all data) to another server and return the data from that server.
So the above CURL command should, for example, send/return data to/from 'https://127.0.0.1:443' instead of 'https://httpbin.org/anything'. Is it possible to do it with 'http-mitm-proxy'? My current code is as follows:
Thank you in advance for any help.
The text was updated successfully, but these errors were encountered: