PageRenderTime 68ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/node_modules/follow-redirects/README.md

https://bitbucket.org/alan_doyle/movie
Markdown | 135 lines | 100 code | 35 blank | 0 comment | 0 complexity | 18fa3ce91a9673545a47cd04dd1026e6 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, Unlicense, BSD-2-Clause, MIT, BSD-3-Clause, Apache-2.0, CC-BY-4.0, GPL-2.0, 0BSD, JSON
  1. ## Follow Redirects
  2. Drop-in replacement for Nodes `http` and `https` that automatically follows redirects.
  3. [![npm version](https://badge.fury.io/js/follow-redirects.svg)](https://www.npmjs.com/package/follow-redirects)
  4. [![Build Status](https://travis-ci.org/olalonde/follow-redirects.svg?branch=master)](https://travis-ci.org/olalonde/follow-redirects)
  5. [![Coverage Status](https://coveralls.io/repos/olalonde/follow-redirects/badge.svg?branch=master)](https://coveralls.io/r/olalonde/follow-redirects?branch=master)
  6. [![Code Climate](https://codeclimate.com/github/olalonde/follow-redirects/badges/gpa.svg)](https://codeclimate.com/github/olalonde/follow-redirects)
  7. [![Dependency Status](https://david-dm.org/olalonde/follow-redirects.svg)](https://david-dm.org/olalonde/follow-redirects)
  8. [![devDependency Status](https://david-dm.org/olalonde/follow-redirects/dev-status.svg)](https://david-dm.org/olalonde/follow-redirects#info=devDependencies)
  9. [![NPM](https://nodei.co/npm/follow-redirects.png?downloads=true)](https://nodei.co/npm/follow-redirects/)
  10. `follow-redirects` provides [request](https://nodejs.org/api/http.html#http_http_request_options_callback) and [get](https://nodejs.org/api/http.html#http_http_get_options_callback)
  11. methods that behave identically to those found on the native [http](https://nodejs.org/api/http.html#http_http_request_options_callback) and [https](https://nodejs.org/api/https.html#https_https_request_options_callback)
  12. modules, with the exception that they will seamlessly follow redirects.
  13. ```javascript
  14. var http = require('follow-redirects').http;
  15. var https = require('follow-redirects').https;
  16. http.get('http://bit.ly/900913', function (response) {
  17. response.on('data', function (chunk) {
  18. console.log(chunk);
  19. });
  20. }).on('error', function (err) {
  21. console.error(err);
  22. });
  23. ```
  24. You can inspect the final redirected URL through the `responseUrl` property on the `response`.
  25. If no redirection happened, `responseUrl` is the original request URL.
  26. ```javascript
  27. https.request({
  28. host: 'bitly.com',
  29. path: '/UHfDGO',
  30. }, function (response) {
  31. console.log(response.responseUrl);
  32. // 'http://duckduckgo.com/robots.txt'
  33. });
  34. ```
  35. ## Options
  36. ### Global options
  37. Global options are set directly on the `follow-redirects` module:
  38. ```javascript
  39. var followRedirects = require('follow-redirects');
  40. followRedirects.maxRedirects = 10;
  41. ```
  42. The following global options are supported:
  43. - `maxRedirects` (default: `21`) sets the maximum number of allowed redirects; if exceeded, an error will be emitted.
  44. ### Per-request options
  45. Per-request options are set by passing an `options` object:
  46. ```javascript
  47. var url = require('url');
  48. var followRedirects = require('follow-redirects');
  49. var options = url.parse('http://bit.ly/900913');
  50. options.maxRedirects = 10;
  51. http.request(options);
  52. ```
  53. In addition to the [standard HTTP](https://nodejs.org/api/http.html#http_http_request_options_callback) and [HTTPS options](https://nodejs.org/api/https.html#https_https_request_options_callback),
  54. the following per-request options are supported:
  55. - `followRedirects` (default: `true`) whether redirects should be followed.
  56. - `maxRedirects` (default: `21`) sets the maximum number of allowed redirects; if exceeded, an error will be emitted.
  57. - `agents` (default: `undefined`) sets the `agent` option per protocol, since HTTP and HTTPS use different agents. Example value: `{ http: new http.Agent(), https: new https.Agent() }`
  58. ## Browserify Usage
  59. Due to the way `XMLHttpRequest` works, the `browserify` versions of `http` and `https` already follow redirects.
  60. If you are *only* targeting the browser, then this library has little value for you. If you want to write cross
  61. platform code for node and the browser, `follow-redirects` provides a great solution for making the native node
  62. modules behave the same as they do in browserified builds in the browser. To avoid bundling unnecessary code
  63. you should tell browserify to swap out `follow-redirects` with the standard modules when bundling.
  64. To make this easier, you need to change how you require the modules:
  65. ```javascript
  66. var http = require('follow-redirects/http');
  67. var https = require('follow-redirects/https');
  68. ```
  69. You can then replace `follow-redirects` in your browserify configuration like so:
  70. ```javascript
  71. "browser": {
  72. "follow-redirects/http" : "http",
  73. "follow-redirects/https" : "https"
  74. }
  75. ```
  76. The `browserify-http` module has not kept pace with node development, and no long behaves identically to the native
  77. module when running in the browser. If you are experiencing problems, you may want to check out
  78. [browserify-http-2](https://www.npmjs.com/package/http-browserify-2). It is more actively maintained and
  79. attempts to address a few of the shortcomings of `browserify-http`. In that case, your browserify config should
  80. look something like this:
  81. ```javascript
  82. "browser": {
  83. "follow-redirects/http" : "browserify-http-2/http",
  84. "follow-redirects/https" : "browserify-http-2/https"
  85. }
  86. ```
  87. ## Contributing
  88. Pull Requests are always welcome. Please [file an issue](https://github.com/olalonde/follow-redirects/issues)
  89. detailing your proposal before you invest your valuable time. Additional features and bug fixes should be accompanied
  90. by tests. You can run the test suite locally with a simple `npm test` command.
  91. ## Debug Logging
  92. `follow-redirects` uses the excellent [debug](https://www.npmjs.com/package/debug) for logging. To turn on logging
  93. set the environment variable `DEBUG=follow-redirects` for debug output from just this module. When running the test
  94. suite it is sometimes advantageous to set `DEBUG=*` to see output from the express server as well.
  95. ## Authors
  96. - Olivier Lalonde (olalonde@gmail.com)
  97. - James Talmage (james@talmage.io)
  98. - [Ruben Verborgh](https://ruben.verborgh.org/)
  99. ## License
  100. MIT: [http://olalonde.mit-license.org](http://olalonde.mit-license.org)