How to use the mockttp.matchers function in mockttp

To help you get started, we’ve selected a few mockttp 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 opticdev / optic / api-cli / src / commands / intercept.ts View on Github external
const https = {
      certPath,
      keyPath
    }

    const proxy = mockttp.getLocal({
      cors: true,
      debug: false,
      https,
      recordTraffic: false
    })
    this.proxy = proxy
    proxy.addRules(
      {
        matchers: [
          new mockttp.matchers.HostMatcher('amiusing.httptoolkit.tech')
        ],
        handler: new mockttp.handlers.CallbackHandler(request => {
          const response: CallbackResponseResult = {
            statusCode: 302,
            headers: {
              location: `https://${config.targetHost}`
            }
          }
          return response
        })
      },
      {
        matchers: [
          new mockttp.matchers.WildcardMatcher()
        ],
        handler: new mockttp.handlers.PassThroughHandler()
github opticdev / optic / api-cli / src / lib / TransparentProxyCaptureSession.ts View on Github external
const https = {
      certPath,
      keyPath
    }

    const proxy = mockttp.getLocal({
      cors: true,
      debug: false,
      https,
      recordTraffic: false
    })
    this.proxy = proxy;
    proxy.addRules(
      {
        matchers: [
          new mockttp.matchers.WildcardMatcher()
        ],
        handler: new mockttp.handlers.PassThroughHandler()
      }
    )

    proxy.on('request', (req: mockttp.CompletedRequest) => {
      if (config.targetHosts.includes(req.headers.host)) {
        this.requests.set(req.id, req)
      } else {
        this.unknownHosts.push(normalizeHost(req.headers.host))
      }
    })

    proxy.on('response', (res: mockttp.CompletedResponse) => {
      if (this.requests.has(res.id)) {
        const req = this.requests.get(res.id) as mockttp.CompletedRequest
github opticdev / optic / api-cli / src / commands / intercept.ts View on Github external
matchers: [
          new mockttp.matchers.HostMatcher('amiusing.httptoolkit.tech')
        ],
        handler: new mockttp.handlers.CallbackHandler(request => {
          const response: CallbackResponseResult = {
            statusCode: 302,
            headers: {
              location: `https://${config.targetHost}`
            }
          }
          return response
        })
      },
      {
        matchers: [
          new mockttp.matchers.WildcardMatcher()
        ],
        handler: new mockttp.handlers.PassThroughHandler()
      }
    )

    proxy.on('request', (req: mockttp.CompletedRequest) => {
      if (req.headers.host === config.targetHost) {
        this.requests.set(req.id, req)
      }
    })

    proxy.on('response', (res: mockttp.CompletedResponse) => {
      if (this.requests.has(res.id)) {
        const req = this.requests.get(res.id) as mockttp.CompletedRequest
        const queryString: string = url.parse(req.url).query || ''
        const queryParameters = qs.parse(queryString)

mockttp

Mock HTTP server for testing HTTP clients and stubbing webservices

Apache-2.0
Latest version published 16 days ago

Package Health Score

80 / 100
Full package analysis