@ya-lsy/proxy
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

proxy

simple http proxy

example

import * as http from "http";
import * as https from "https";
import Proxy from "@ya-lsy/proxy";

class MyProxyServer extends Proxy {

  constructor(server: http.Server | https.Server) {
    super(server);
  }

  authorization(req: http.IncomingMessage): boolean {
    return true;
  }

  direct(req: http.IncomingMessage, res: http.ServerResponse) {
    res.end('hello world');
  }

  onerror(type: 'request' | 'connect', req: http.IncomingMessage) {
    console.log('onerror:', type, req.socket.remoteAddress, req.url);
  }

  onproxy(type: 'request' | 'connect', req: http.IncomingMessage) {
    console.log('onproxy:', type, req.socket.remoteAddress, req.url);
  }
}

const server = http.createServer();

const proxy = new MyProxyServer(server);

server.listen(8080);

You can test curl -vv --proxy http://localhost:8080 https://github.com js will print onproxy: connect ::ffff:127.0.0.1 github.com:443

Readme

Keywords

Package Sidebar

Install

npm i @ya-lsy/proxy

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

12.3 kB

Total Files

6

Last publish

Collaborators

  • ya-lsy