0.1.1 • Published 2 years ago

pooy-core v0.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

pooy-core

Node version npm version NPM

中文文档

A proxy service based on NodeJS EventEmitter. It can realize request monitoring and packet capture, support modification request body and response body, and provide secondary development capability at each stage of the request.

Installation

Pooy requires node v7.6.0 or higher for ES2015 and async function support.

⚠️ Because it involves an automatic installation update of the self-signed root certificate, it is necessary to run with the administrator privileges.

npm install pooy

Example

const Pooy = require('pooy');
const proxy = new Pooy();

proxy.on('error', (err, ctx) => {
  console.log('oops, something went wrong!', err);
  consle.log(ctx);
});

proxy.on('request', (ctx) => {
  consle.log(ctx.method, ctx.protocol, ctx.host, ctx.url);
});

proxy.on('response', (ctx) => {
  ctx.setHeader('proxy-agent', 'pooy');
});

proxy.listen(9696, () => {
  console.log('proxy server run at 9696...');
});

Events

A complete request response in pooy will go through four kinds of events:

  • request
  • requestEnd
  • response
  • responseEnd

which will trigger the error event when an unexpected error occurs.

Context

In each event callback, there is a context object that wraps its own response and request objects, as well as the original request or response objects clientRequest and remoteResponse that mount the current event. Additional for easy modification or retrieval of some request or response body related information context also provides setHeader getHeader removeHeader setBody getBody and other series of method functions

Document

TODO

⚠️ Platform compatibility (currently only supports macOS)

License

MIT

0.1.1

2 years ago

0.1.0

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.2

5 years ago

0.0.1

5 years ago

0.0.1-beta1

5 years ago

0.0.1-beta

5 years ago