1.0.7 • Published 7 years ago

node-http-intercept v1.0.7

Weekly downloads
5
License
(MIT OR Apache-2....
Repository
github
Last release
7 years ago

http-intercept

Intercepts node http.request. Allows conditional request modification.

Install

Install with npm

$ npm i http-intercept --save-dev

Usage

  const httpIntercept = require('http-intercept');
  const options = {
    hostname: 'google.com',
    port: 80,
    path: '/upload',
    method: 'get',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
  };

  const interceptOptions = {
    searchValue: 'google',
    replaceValue: 'bing',
    callback: (newOptions) => {
      // newOptions.hostname ==='bing.com
    },
  };

  httpIntercept(interceptOptions);

  http.request(options);
  const httpIntercept = require('http-intercept');
  const options = {
    hostname: 'google.com',
    port: 80,
    path: '/upload',
    method: 'get',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
  };

  const interceptOptions = {
    searchValue: 'google',
    replaceValue: 'bing',
    callback: (newOptions) => {
      // newOptions is unchanged because predicate fails.
    },
    predicate: () => false,
  };

  httpIntercept(interceptOptions);

  http.request(options);
  const httpIntercept = require('http-intercept');
  const options = {
    hostname: 'google.com',
    port: 80,
    path: '/upload',
    method: 'get',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
  };

  const interceptOptions = {
    searchAndReplaceValues: [{
      google: 'bing',
    },
    {
      '.com': '.org',
    },
    ],
    callback: (newOptions) => {
      // hostname is now 'bing.org'
    },
  };

  httpIntercept(interceptOptions);

  http.request(options);

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

Jeff Wilde

License

Copyright © 2017 Jeff Wilde(#Jeff Wilde) Licensed under the (MIT OR Apache-2.0) license.


This file was generated by readme-generator on January 26, 2017.

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago