1.0.1 • Published 7 years ago

osniffer v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

osniffer

HTTP通信を覗き見るためのプロキシを作るライブラリです.

Install

npm install osniffer

Requirements

Node.js >= 7.6.0

Example

content-typeがapplication/jsonの通信をconsoleに出力する例

const zlib = require("zlib");

const es = require("event-stream");

const Sniffer = require("osniffer");
const sniffer = new Sniffer();

sniffer.use(async (ctx, next) => {
    if (ctx.response.headers["content-type"] === "application/json") {
        await next();
    }
});
sniffer.use(async (ctx, next) => {
    ctx.response
        .pipe(zlib.createGunzip())
        .pipe(es.wait())
        .pipe(es.parse())
        .pipe(es.map(x => console.log(x)));
    await next();
});
sniffer.listen(8080);