How to use the mitm function in mitm

To help you get started, we’ve selected a few mitm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FormidableLabs / yesno / src / interceptor.ts View on Github external
public enable(options: IInterceptOptions = {}): void {
    // switch comparator functions when specified
    this.comparatorFn =
      options.comparatorFn === undefined ? this.comparatorFn : options.comparatorFn;

    if (this.mitm || this.origOnSocket) {
      debug('Interceptor already enabled. Do nothing.');
      return;
    }

    const self = this;
    this.mitm = Mitm();
    this.ignorePorts = options.ignorePorts || [];
    this.origOnSocket = ClientRequest.prototype.onSocket;

    ClientRequest.prototype.onSocket = _.flowRight(
      this.origOnSocket,
      // tslint:disable-next-line:only-arrow-functions
      function(this: ClientRequestFull, socket: RegisteredSocket): RegisteredSocket {
        if (undefined !== socket.__yesno_req_id) {
          debug('New socket on client request', socket.__yesno_req_id);
          self.clientRequests[socket.__yesno_req_id].clientRequest = this;
          this.setHeader(YESNO_INTERNAL_HTTP_HEADER, socket.__yesno_req_id);
        }

        return socket;
      },
    );
github jessestuart / gatsby-source-s3-image / src / __tests__ / source-nodes.spec.ts View on Github external
beforeAll(() => {
    Mitm().on('request', req => {
      const host = _.get(req, 'headers.host')
      const url = _.get(req, 'url')
      throw new Error(
        `Network requests forbidden in offline mode. Tried to call URL "${host}${url}"`
      )
    })
  })
github pact-foundation / pact-js / src / interceptor / index.js View on Github external
constructor (proxyHost) {
    if (isNil(proxyHost)) {
      throw new Error('Please provide a proxy to route the request to.')
    }

    this.whitelist = [ parseUrl(proxyHost) ]
    this.mitm = Mitm()
    this.mitm.disable()
    this.disabled = true
    this.proxyHost = proxyHost
  }
github pact-foundation / pact-js / src / pact-consumer-dsl / interceptor.js View on Github external
constructor (proxyHost) {
    if (isNil(proxyHost)) {
      throw new Error('Please provide a proxy to route the request to.')
    }

    this.whitelist = [ parseUrl(proxyHost) ]
    this.mitm = Mitm()
    this.mitm.disable()
    this.disabled = true
    this.proxyHost = proxyHost
  }

mitm

Intercept and mock outgoing network TCP connections and HTTP requests for testing. Intercepts and gives you a Net.Socket, Http.IncomingMessage and Http.ServerResponse to test and respond with. Useful when testing code that hits remote servers.

AGPL-3.0-or-later WITH GPL-3.…
Latest version published 4 months ago

Package Health Score

64 / 100
Full package analysis

Popular mitm functions