PageRenderTime 24ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/packages/atom-beautify/node_modules/follow-redirects/README.md

https://gitlab.com/xanium4332/atom-config
Markdown | 112 lines | 85 code | 27 blank | 0 comment | 0 complexity | 19bd2f0f4045a161bb95a1978c3b81aa MD5 | raw file
  1. ## Follow Redirects
  2. Drop in replacement for Nodes `http` and `https` that automatically follows redirects.
  3. [![Build Status](https://travis-ci.org/olalonde/follow-redirects.svg?branch=master)](https://travis-ci.org/olalonde/follow-redirects)
  4. [![Coverage Status](https://coveralls.io/repos/olalonde/follow-redirects/badge.svg?branch=master)](https://coveralls.io/r/olalonde/follow-redirects?branch=master)
  5. [![Code Climate](https://codeclimate.com/github/olalonde/follow-redirects/badges/gpa.svg)](https://codeclimate.com/github/olalonde/follow-redirects)
  6. [![Dependency Status](https://david-dm.org/olalonde/follow-redirects.svg)](https://david-dm.org/olalonde/follow-redirects)
  7. [![devDependency Status](https://david-dm.org/olalonde/follow-redirects/dev-status.svg)](https://david-dm.org/olalonde/follow-redirects#info=devDependencies)
  8. [![NPM](https://nodei.co/npm/follow-redirects.png?downloads=true)](https://nodei.co/npm/follow-redirects/)
  9. `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)
  10. 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)
  11. modules, with the exception that they will seamlessly follow redirects.
  12. ```javascript
  13. var http = require('follow-redirects').http;
  14. var https = require('follow-redirects').https;
  15. http.get('http://bit.ly/900913', function (res) {
  16. res.on('data', function (chunk) {
  17. console.log(chunk);
  18. });
  19. }).on('error', function (err) {
  20. console.error(err);
  21. });
  22. ```
  23. By default the number of redirects is limited to 5, but you can modify that globally or per request.
  24. ```javascript
  25. require('follow-redirects').maxRedirects = 10; // Has global affect (be careful!)
  26. https.request({
  27. host: 'bitly.com',
  28. path: '/UHfDGO',
  29. maxRedirects: 3 // per request setting
  30. }, function (res) {/* ... */});
  31. ```
  32. You can inspect the redirection chain from the `fetchedUrls` array on the `response`.
  33. The array is populated in reverse order, so the original url you requested will be the
  34. last element, while the final redirection point will be at index 0.
  35. ```javascript
  36. https.request({
  37. host: 'bitly.com',
  38. path: '/UHfDGO',
  39. }, function (res) {
  40. console.log(res.fetchedUrls);
  41. // [ 'http://duckduckgo.com/robots.txt', 'http://bitly.com/UHfDGO' ]
  42. });
  43. ```
  44. ## Browserify Usage
  45. Due to the way `XMLHttpRequest` works, the `browserify` versions of `http` and `https` already follow redirects.
  46. If you are *only* targetting the browser, then this library has little value for you. If you want to write cross
  47. platform code for node and the browser, `follow-redirects` provides a great solution for making the native node
  48. modules behave the same as they do in browserified builds in the browser. To avoid bundling unnecessary code
  49. you should tell browserify to swap out `follow-redirects` with the standard modules when bundling.
  50. To make this easier, you need to change how you require the modules:
  51. ```javascript
  52. var http = require('follow-redirects/http');
  53. var https = require('follow-redirects/https');
  54. ```
  55. You can then replace `follow-redirects` in your browserify configuration like so:
  56. ```javascript
  57. "browser": {
  58. "follow-redirects/http" : "http",
  59. "follow-redirects/https" : "https"
  60. }
  61. ```
  62. The `browserify-http` module has not kept pace with node development, and no long behaves identically to the native
  63. module when running in the browser. If you are experiencing problems, you may want to check out
  64. [browserify-http-2](https://www.npmjs.com/package/http-browserify-2). It is more actively maintained and
  65. attempts to address a few of the shortcomings of `browserify-http`. In that case, your browserify config should
  66. look something like this:
  67. ```javascript
  68. "browser": {
  69. "follow-redirects/http" : "browserify-http-2/http",
  70. "follow-redirects/https" : "browserify-http-2/https"
  71. }
  72. ```
  73. ## Contributing
  74. Pull Requests are always welcome. Please [file an issue](https://github.com/olalonde/follow-redirects/issues)
  75. detailing your proposal before you invest your valuable time. Additional features and bug fixes should be accompanied
  76. by tests. You can run the test suite locally with a simple `npm test` command.
  77. ## Debug Logging
  78. `follow-redirects` uses the excellent [debug](https://www.npmjs.com/package/debug) for logging. To turn on logging
  79. set the environment variable `DEBUG=follow-redirects` for debug output from just this module. When running the test
  80. suite it is sometimes advantageous to set `DEBUG=*` to see output from the express server as well.
  81. ## Authors
  82. Olivier Lalonde (olalonde@gmail.com)
  83. James Talmage (james@talmage.io)
  84. ## License
  85. MIT: [http://olalonde.mit-license.org](http://olalonde.mit-license.org)