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

/reservi/app/node_modules/follow-redirects/README.md

https://bitbucket.org/roko_cleiton_brustulin/roko_ciklus
Markdown | 146 lines | 109 code | 37 blank | 0 comment | 0 complexity | 5a6123170b65912c917cd839c75bdf2d MD5 | raw file
Possible License(s): LGPL-2.1, 0BSD, Unlicense, BSD-2-Clause, MIT, Apache-2.0, JSON, CC-BY-SA-3.0, BSD-3-Clause
  1. ## Follow Redirects
  2. Drop-in replacement for Node's `http` and `https` modules that automatically follows redirects.
  3. [![npm version](https://img.shields.io/npm/v/follow-redirects.svg)](https://www.npmjs.com/package/follow-redirects)
  4. [![Build Status](https://travis-ci.org/follow-redirects/follow-redirects.svg?branch=master)](https://travis-ci.org/follow-redirects/follow-redirects)
  5. [![Coverage Status](https://coveralls.io/repos/follow-redirects/follow-redirects/badge.svg?branch=master)](https://coveralls.io/r/follow-redirects/follow-redirects?branch=master)
  6. [![npm downloads](https://img.shields.io/npm/dm/follow-redirects.svg)](https://www.npmjs.com/package/follow-redirects)
  7. [![Sponsor on GitHub](https://img.shields.io/static/v1?label=Sponsor&message=%F0%9F%92%96&logo=GitHub)](https://github.com/sponsors/RubenVerborgh)
  8. `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)
  9. 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)
  10. modules, with the exception that they will seamlessly follow redirects.
  11. ```javascript
  12. const { http, https } = require('follow-redirects');
  13. http.get('http://bit.ly/900913', response => {
  14. response.on('data', chunk => {
  15. console.log(chunk);
  16. });
  17. }).on('error', err => {
  18. console.error(err);
  19. });
  20. ```
  21. You can inspect the final redirected URL through the `responseUrl` property on the `response`.
  22. If no redirection happened, `responseUrl` is the original request URL.
  23. ```javascript
  24. https.request({
  25. host: 'bitly.com',
  26. path: '/UHfDGO',
  27. }, response => {
  28. console.log(response.responseUrl);
  29. // 'http://duckduckgo.com/robots.txt'
  30. });
  31. ```
  32. ## Options
  33. ### Global options
  34. Global options are set directly on the `follow-redirects` module:
  35. ```javascript
  36. const followRedirects = require('follow-redirects');
  37. followRedirects.maxRedirects = 10;
  38. followRedirects.maxBodyLength = 20 * 1024 * 1024; // 20 MB
  39. ```
  40. The following global options are supported:
  41. - `maxRedirects` (default: `21`) sets the maximum number of allowed redirects; if exceeded, an error will be emitted.
  42. - `maxBodyLength` (default: 10MB) sets the maximum size of the request body; if exceeded, an error will be emitted.
  43. ### Per-request options
  44. Per-request options are set by passing an `options` object:
  45. ```javascript
  46. const url = require('url');
  47. const { http, https } = require('follow-redirects');
  48. const options = url.parse('http://bit.ly/900913');
  49. options.maxRedirects = 10;
  50. options.beforeRedirect = options => {
  51. // Use this function to adjust the options upon redirecting,
  52. // or to cancel the request by throwing an error
  53. if (options.hostname === "example.com") {
  54. options.auth = "user:password";
  55. }
  56. };
  57. http.request(options);
  58. ```
  59. 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),
  60. the following per-request options are supported:
  61. - `followRedirects` (default: `true`) whether redirects should be followed.
  62. - `maxRedirects` (default: `21`) sets the maximum number of allowed redirects; if exceeded, an error will be emitted.
  63. - `maxBodyLength` (default: 10MB) sets the maximum size of the request body; if exceeded, an error will be emitted.
  64. - `beforeRedirect` (default: `undefined`) optionally change the request `options` on redirects, or abort the request by throwing an error.
  65. - `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() }`
  66. - `trackRedirects` (default: `false`) whether to store the redirected response details into the `redirects` array on the response object.
  67. ### Advanced usage
  68. By default, `follow-redirects` will use the Node.js default implementations
  69. of [`http`](https://nodejs.org/api/http.html)
  70. and [`https`](https://nodejs.org/api/https.html).
  71. To enable features such as caching and/or intermediate request tracking,
  72. you might instead want to wrap `follow-redirects` around custom protocol implementations:
  73. ```javascript
  74. const { http, https } = require('follow-redirects').wrap({
  75. http: require('your-custom-http'),
  76. https: require('your-custom-https'),
  77. });
  78. ```
  79. Such custom protocols only need an implementation of the `request` method.
  80. ## Browser Usage
  81. Due to the way the browser works,
  82. the `http` and `https` browser equivalents perform redirects by default.
  83. By requiring `follow-redirects` this way:
  84. ```javascript
  85. const http = require('follow-redirects/http');
  86. const https = require('follow-redirects/https');
  87. ```
  88. you can easily tell webpack and friends to replace
  89. `follow-redirect` by the built-in versions:
  90. ```json
  91. {
  92. "follow-redirects/http" : "http",
  93. "follow-redirects/https" : "https"
  94. }
  95. ```
  96. ## Contributing
  97. Pull Requests are always welcome. Please [file an issue](https://github.com/follow-redirects/follow-redirects/issues)
  98. detailing your proposal before you invest your valuable time. Additional features and bug fixes should be accompanied
  99. by tests. You can run the test suite locally with a simple `npm test` command.
  100. ## Debug Logging
  101. `follow-redirects` uses the excellent [debug](https://www.npmjs.com/package/debug) for logging. To turn on logging
  102. set the environment variable `DEBUG=follow-redirects` for debug output from just this module. When running the test
  103. suite it is sometimes advantageous to set `DEBUG=*` to see output from the express server as well.
  104. ## Authors
  105. - [Ruben Verborgh](https://ruben.verborgh.org/)
  106. - [Olivier Lalonde](mailto:olalonde@gmail.com)
  107. - [James Talmage](mailto:james@talmage.io)
  108. ## License
  109. [MIT License](https://github.com/follow-redirects/follow-redirects/blob/master/LICENSE)