a http proxy to non-blocking inspect request / response
yarn add https://github.com/LightouchDev/inspectProxyinspectProxy inherits from http.Server and has the following additional events:
request<Object>url<String> Request urlbody<Buffer> Request message bodyheaders<Object> Request header
Emitted each time there is a request. body may be an empty <Buffer>, append toString() to inspect content.
request<Object>url<String> Origin request urlbody<Buffer> Response message bodyheaders<Object> Response header
Emitted each time when a response is received. body may be an empty <Buffer>, append toString() to inspect content.
request<http.IncomingMessage>response<http.ServerResponse>
It's emitted in request event, and emitted only when request url is not contained hostname.
# this emit event
$ curl http://PROXY-ADDRESS:PORT/some-path # request.url === '/some-path'
# this wouldn't
$ curl --proxy http://PROXY-ADDRESS:PORT/ http://example.com/ # request.url === 'http://example.com/'The port that proxy using for listening. only available after listening event emitted.
The switch to decompress message body from remote response according to Content-Encoding header. default: true
callback<Function>clientRequest<http.IncomingMessage> Request from client
Set which request condition should be inspected, callback should return true to inspect current request.
callback<Function>clientRequest<http.IncomingMessage> Request from clientremoteResponse<http.IncomingMessage> Response from remote server
Set which response condition should be inspected, callback should return true to inspect current response.
- basePort <Number> The base port to start finding. default:
8000
Proxy would check available port and start listening. if port unavailable, it would try next port until found.
As http.listen(), it would emit listening event when proxy start listening.
See example
- Design reference: AnyProxy
- No https inspect
- All https connection is bypassed.
- No websocket inspect
- Websocket support is in plan, but no ETA.
- Performance cost
- This proxy add about 5~7ms latency in each response with about 0.035% response lost.
- (test in vegeta with gzip-enabled nginx default page)
MIT