alibaba / anyproxy

A fully configurable http/https proxy in NodeJS
http://anyproxy.io
Apache License 2.0
7.85k stars 1.22k forks source link

无法修改 HTTPS 的请求目标地址 #587

Closed smalldragonluo closed 2 years ago

smalldragonluo commented 3 years ago

Which platform are you running AnyProxy

Mac

The version of the AnyProxy

4.1.3

Your expected behavior of AnyProxy

修改 HTTPS 的请求 host

async beforeSendRequest(requestDetail: RequestDetail) {
  const newRequestOptions = requestDetail.requestOptions;
  requestDetail.protocol = 'https';
  newRequestOptions.host = 'www.baidu.com';
  newRequestOptions.port = 443;
  newRequestOptions.path = '/';
  newRequestOptions.method = 'GET';
  return requestDetail;
}

The actual behavior of AnyProxy

并未成功修改目标地址,页面和之前请求一样

The log of the error

/usr/local/bin/node /usr/local/lib/node_modules/npm/bin/npm-cli.js run start --scripts-prepend-node-path=auto Debugger listening on ws://127.0.0.1:58400/e7bb5194-1b86-4949-9266-8242c2e7a2ce For help, see: https://nodejs.org/en/docs/inspector Debugger attached.

proxy-rules@1.0.0 start /Users/smaldragonluo/code/personal/proxy-rules anyproxy --intercept --ws-intercept --port 1080 --rule ./lib/rules.js

Debugger listening on ws://127.0.0.1:58407/6ec69c29-c8b6-434a-9ac4-1c1422dc20bb For help, see: https://nodejs.org/en/docs/inspector Debugger attached. [AnyProxy Log][2021-06-25 11:24:16]: Http proxy started on port 1080 [AnyProxy Log][2021-06-25 11:24:16]: web interface started on port 8002 [AnyProxy Log][2021-06-25 11:24:16]: Active rule is: custom rules [AnyProxy Log][2021-06-25 11:24:16]: received https CONNECT request anyproxy.io [AnyProxy Log][2021-06-25 11:24:16]: will forward to local https server [AnyProxy Log][2021-06-25 11:24:16]: [internal https]proxy server for anyproxy.io established [AnyProxy Log][2021-06-25 11:24:16]: received request to: GET anyproxy.io/cn/ [AnyProxy Log][2021-06-25 11:24:17]: received request to: GET anyproxy.io/cn/gitbook/style.css [AnyProxy Log][2021-06-25 11:24:17]: received https CONNECT request anyproxy.io [AnyProxy Log][2021-06-25 11:24:17]: will forward to local https server [AnyProxy Log][2021-06-25 11:24:17]: received request to: GET anyproxy.io/assets/auto-lang.js [AnyProxy Log][2021-06-25 11:24:18]: received request to: GET anyproxy.io/cn/gitbook/images/favicon.ico [AnyProxy Log][2021-06-25 11:24:19]: received https CONNECT request github.com [AnyProxy Log][2021-06-25 11:24:19]: will forward to local https server

Jsnows commented 2 years ago

还需要修改headers里的Host