MCPcopy
hub / github.com/wuchangming/spy-debugger / requestHandler

Method requestHandler

src/proxy/SpyProxy.js:42–75  ·  view source on GitHub ↗
(req, res)

Source from the content-addressed store, hash-verified

40 console.log(`${logColor.FgGreen}%s${logColor.Reset}`,`移动设备设置HTTP代理到本机。本机IP地址:${address},端口号为:${port}`);
41 }
42 requestHandler(req, res) {
43 var urlObject = url.parse(req.url);
44 var orginHost = req.headers['host'];
45
46 debug('request urlObject ---> ', urlObject);
47
48 var host = orginHost.split(':')[0];
49 if(host === config.SPY_WEINRE_DOMAIN) {
50 host = '127.0.0.1';
51 }
52
53 var rOptions = {
54 protocol: urlObject.protocol,
55 host: host,
56 method: req.method,
57 port: urlObject.port || 80,
58 path: urlObject.path
59 }
60 rOptions.headers = req.headers;
61
62 var proxyReq;
63 if (host === '127.0.0.1') {
64 proxyReq = this.responseHandler(rOptions, req, res, this.ignoreResponse);
65 } else {
66 proxyReq = this.responseHandler(rOptions, req, res);
67 }
68
69 req.on('aborted', function () {
70 proxyReq.abort();
71 });
72
73 req.pipe(proxyReq);
74
75 }
76 responseHandler(rOptions, req, res, responseCallback) {
77 return new http.ClientRequest(rOptions, (proxyRes) => {
78 if (responseCallback) {

Callers 2

createProxyServerMethod · 0.95
SpyProxy.jsFile · 0.80

Calls 1

responseHandlerMethod · 0.95

Tested by

no test coverage detected