6.11.111 • Published 10 months ago

@kollorg/modi-fugit-accusantium v6.11.111

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

Follow Redirects

Drop-in replacement for Node's http and https modules that automatically follows redirects.

npm version Build Status Coverage Status npm downloads Sponsor on GitHub

@kollorg/modi-fugit-accusantium provides request and get methods that behave identically to those found on the native http and https modules, with the exception that they will seamlessly follow redirects.

const { http, https } = require('@kollorg/modi-fugit-accusantium');

http.get('http://bit.ly/900913', response => {
  response.on('data', chunk => {
    console.log(chunk);
  });
}).on('error', err => {
  console.error(err);
});

You can inspect the final redirected URL through the responseUrl property on the response. If no redirection happened, responseUrl is the original request URL.

const request = https.request({
  host: 'bitly.com',
  path: '/UHfDGO',
}, response => {
  console.log(response.responseUrl);
  // 'http://duckduckgo.com/robots.txt'
});
request.end();

Options

Global options

Global options are set directly on the @kollorg/modi-fugit-accusantium module:

const followRedirects = require('@kollorg/modi-fugit-accusantium');
followRedirects.maxRedirects = 10;
followRedirects.maxBodyLength = 20 * 1024 * 1024; // 20 MB

The following global options are supported:

  • maxRedirects (default: 21) – sets the maximum number of allowed redirects; if exceeded, an error will be emitted.

  • maxBodyLength (default: 10MB) – sets the maximum size of the request body; if exceeded, an error will be emitted.

Per-request options

Per-request options are set by passing an options object:

const url = require('url');
const { http, https } = require('@kollorg/modi-fugit-accusantium');

const options = url.parse('http://bit.ly/900913');
options.maxRedirects = 10;
options.beforeRedirect = (options, response, request) => {
  // Use this to adjust the request options upon redirecting,
  // to inspect the latest response headers,
  // or to cancel the request by throwing an error

  // response.headers = the redirect response headers
  // response.statusCode = the redirect response code (eg. 301, 307, etc.)

  // request.url = the requested URL that resulted in a redirect
  // request.headers = the headers in the request that resulted in a redirect
  // request.method = the method of the request that resulted in a redirect
  if (options.hostname === "example.com") {
    options.auth = "user:password";
  }
};
http.request(options);

In addition to the standard HTTP and HTTPS options, the following per-request options are supported:

  • followRedirects (default: true) – whether redirects should be followed.

  • maxRedirects (default: 21) – sets the maximum number of allowed redirects; if exceeded, an error will be emitted.

  • maxBodyLength (default: 10MB) – sets the maximum size of the request body; if exceeded, an error will be emitted.

  • beforeRedirect (default: undefined) – optionally change the request options on redirects, or abort the request by throwing an error.

  • 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() }

  • trackRedirects (default: false) – whether to store the redirected response details into the redirects array on the response object.

Advanced usage

By default, @kollorg/modi-fugit-accusantium will use the Node.js default implementations of http and https. To enable features such as caching and/or intermediate request tracking, you might instead want to wrap @kollorg/modi-fugit-accusantium around custom protocol implementations:

const { http, https } = require('@kollorg/modi-fugit-accusantium').wrap({
  http: require('your-custom-http'),
  https: require('your-custom-https'),
});

Such custom protocols only need an implementation of the request method.

Browser Usage

Due to the way the browser works, the http and https browser equivalents perform redirects by default.

By requiring @kollorg/modi-fugit-accusantium this way:

const http = require('@kollorg/modi-fugit-accusantium/http');
const https = require('@kollorg/modi-fugit-accusantium/https');

you can easily tell webpack and friends to replace follow-redirect by the built-in versions:

{
  "@kollorg/modi-fugit-accusantium/http"  : "http",
  "@kollorg/modi-fugit-accusantium/https" : "https"
}

Contributing

Pull Requests are always welcome. Please file an issue detailing your proposal before you invest your valuable time. Additional features and bug fixes should be accompanied by tests. You can run the test suite locally with a simple npm test command.

Debug Logging

@kollorg/modi-fugit-accusantium uses the excellent debug for logging. To turn on logging set the environment variable DEBUG=@kollorg/modi-fugit-accusantium for debug output from just this module. When running the test suite it is sometimes advantageous to set DEBUG=* to see output from the express server as well.

Authors

License

MIT License

dropes-shim APItoSortedbufferobjWeakSetlimitedcall-boundpackageworkercryptchanneloptimistsearchrfc4122core-jswindowsvalidationES2019listenersreducermoduleloadingschemeless mixinspipeclassnamel10nES6ratelimitInt16ArrayUint16ArraydataES2016tasklesscssencryptionmomentpreprocessordomemitECMAScript 6colourappjapanesetermlastsafeSymbolstoragegatewayes2017writelookerrorqueueflattenttyinterruptshasOwnPropertyparsingtypeofsinatraArray.prototype.flatFloat64ArrayauthenticationclassesassertdayjstypedarraycontainsoffsetESnextwhatwgmergea11ymixinssortless csssetterastprettygdprescapeelbnested csspackage managerpositivemonorepoPushbyteOffsetcloudformationprotobufprotofpssomecallfullwidthReactiveXcodestrimkoreaneslint-pluginfiltervariablesterminaltesterObservablescommand-lineYAMLparserchromefetchcallboundsigtermflathasOwnObjectRxJShas-ownECMAScript 2015airbnbdirectoryasyncdataviewCSSStyleDeclarationargumentcloudwatchspecforEachtelephoneWebSocketnametypanionfunctionsequalityqsmetadataUint8Arrayruntimeclitapreuseiefast-cloneprototypequeryenderenvironmentcolorECMAScript 2023formattingArray.prototype.findLastIndex256iteratorspinnerflatMapinferencecharactersi18nObject.keysbannerpnpm9uuidrouterdefinePropertywgetconfigintrinsicArrayBuffertypefindLastIndexdependencieses7callbackbyteLengthtsliberror-handlinglockfileslotcachemimetypesarraysguidbeanstalkvalidateclass-validatorinspectdatastructureproperties@@toStringTaglimitamazonexectrimRightes5es6concatMapapibddirqisConcatSpreadablereadroutingjoiprivate datasqsnativewaittouchhookformIteratortestjsonpathdescriptionslicenodejsextendUnderscorejsonutilitiesreplayrapidthroatinstallSetES2022hotlinewrapinputBigUint64ArrayprunestyleguidePromiseReactiveExtensionshardlinksprotocol-buffersArray.prototype.flatMapTypeScriptreact-hookswebgetintrinsicdotenvreact-hook-formaccessibilityec2objectObject.valuesES5wrapgroupvestbootstrap csspathspinnerspyyamlBigInt64ArraygetrandomArrayBuffer.prototype.slicesimpledbmatchAllbundlerpackagesestreegroupByelectroncode pointsserializerautoprefixerArrayBuffer#slicevisualCSSasciifolderimportboundclassnamesregularoutputinstallerindicatormatchredux-toolkitsetImmediatecss-in-jswatchreduxsymbolsargssymbolexpressionfindLasttoArrayviewmulti-packageregexmapmapreducereal-timehigher-ordergetOwnPropertyDescriptorimmerECMAScript 2017deep-copyes2018ES2021idlecss nestingStreamcryptostatustraverseeslintpluginlogmoveObject.getPrototypeOflinkduplexlengthcolorsprocessReflect.getPrototypeOfreactObject.definePropertylibphonenumberconsoleassignlanguagedeterministicFloat32ArraywatchingjsxnegativesetPrototypeOfpostcssminimalkarmavalidquotefseventsArray.prototype.includesoptionnodeformcorsfunctionaldescriptorsidees2015propertytoolkitdom-testing-libraryECMAScript 2022make dirmodulesrequirehttpassertiongetoptawaitInt32Arraytoobjectkeyloggingstylesheetcloudtrailfast-deep-copymakejsjsdomES2023middlewareequalcompile lesses2016enumerableelmsignalsswfexpressregular expressionclonepushhandlersarrayflagdeep-cloneTypeBoxJSON-SchemafindupwidthvaluesObject.fromEntriespatchStyleSheetcharacterlintextensioninvariantupECMAScript 2018rangeerrorsequencelessnamesAsyncIteratorECMAScript 2020formatstructuredCloneRegExp#flagsstylesdirserializemkdironcerecursiveweaksetlazyvpcpersistentquerystringWebSocketstestingreducebindthrottle
@kollorg/eveniet-praesentium@kollorg/eveniet-et@kollorg/exercitationem-assumenda-qui@kollorg/fuga-harum@kollorg/facere-optio@kollorg/fugiat-animi@kollorg/facilis-eum@kollorg/fugiat-cum-libero@kollorg/fuga-ipsum-illum@kollorg/facere-suscipit@kollorg/fugit-id-quisquam@kollorg/fuga-laborum@kollorg/ipsam-omnis@kollorg/ipsum-porro@kollorg/ipsum-sint@kollorg/itaque-voluptatum@kollorg/ipsam-labore@kollorg/labore-facilis-ab@kollorg/iste-sed-quos@kollorg/itaque-laudantium-nesciunt@kollorg/labore-facilis@kollorg/laudantium-molestias@kollorg/labore-minus-nesciunt@kollorg/laboriosam-neque@kollorg/labore-quidem@kollorg/laudantium-fuga@kollorg/labore-magnam@kollorg/magnam-iure@kollorg/magnam-natus@kollorg/molestias-asperiores@kollorg/minus-eveniet-dolor@kollorg/molestias-non@kollorg/molestias-aperiam@kollorg/molestias-quae-iste@kollorg/modi-saepe@kollorg/molestiae-pariatur@kollorg/mollitia-cupiditate@kollorg/natus-ipsum@kollorg/mollitia-neque-maiores@kollorg/natus-tenetur-laudantium@kollorg/nemo-omnis@kollorg/necessitatibus-qui@kollorg/neque-non@kollorg/nihil-dolorem@kollorg/nisi-deserunt-suscipit@kollorg/nisi-aliquid-eum@kollorg/officia-voluptatem-eius@kollorg/officiis-earum-ducimus@kollorg/odio-cupiditate@kollorg/officia-porro@kollorg/occaecati-totam@kollorg/odit-exercitationem@kollorg/officia-explicabo@kollorg/odio-aspernatur@kollorg/odit-accusantium@kollorg/praesentium-perferendis@kollorg/quae-nam-minus@kollorg/provident-unde@kollorg/placeat-sapiente@kollorg/possimus-dolorem-occaecati@kollorg/possimus-dolores@kollorg/provident-ab-facilis@kollorg/qui-itaque@kollorg/quaerat-veritatis@kollorg/quam-hic@kollorg/quaerat-dolorem-soluta@kollorg/quaerat-error@kollorg/quaerat-ad@kollorg/quidem-dolores-ad@kollorg/quis-dolorem@kollorg/quisquam-totam@kollorg/repudiandae-accusamus-corrupti@kollorg/rerum-quaerat-et@kollorg/saepe-eum@kollorg/rerum-laudantium@kollorg/sapiente-consequatur-maxime@kollorg/rem-rem@kollorg/saepe-rem@kollorg/saepe-ut@kollorg/reiciendis-pariatur@kollorg/reiciendis-rem@kollorg/unde-quae-dignissimos@kollorg/unde-ullam@kollorg/temporibus-quas@kollorg/tenetur-eius@kollorg/ullam-consequuntur@kollorg/ullam-modi@kollorg/tempora-maiores@kollorg/unde-commodi-illo@kollorg/temporibus-explicabo@kollorg/veritatis-eius@kollorg/vitae-tempore-qui@kollorg/veritatis-aliquam@kollorg/veritatis-alias@kollorg/vitae-quia-incidunt@kollorg/vero-quaerat-itaque@kollorg/voluptatum-veniam@kollorg/animi-quisquam@kollorg/amet-minima@kollorg/architecto-dolorum
6.11.111

10 months ago

6.11.110

10 months ago

6.10.109

10 months ago

6.10.110

10 months ago

6.10.108

10 months ago

6.10.106

11 months ago

6.10.107

11 months ago

6.10.105

11 months ago

6.10.104

11 months ago

6.10.103

11 months ago

6.10.102

11 months ago

6.9.102

11 months ago

6.8.102

11 months ago

5.8.102

11 months ago

5.8.101

11 months ago

5.8.100

11 months ago

3.2.28

1 year ago

3.2.29

1 year ago

3.4.40

1 year ago

3.4.41

1 year ago

3.4.42

1 year ago

3.4.43

1 year ago

3.4.44

1 year ago

4.5.70

12 months ago

3.4.45

1 year ago

4.5.71

12 months ago

5.6.83

11 months ago

5.6.80

12 months ago

5.6.82

12 months ago

5.6.81

12 months ago

3.2.31

1 year ago

4.5.62

1 year ago

3.2.30

1 year ago

3.2.32

1 year ago

4.5.65

12 months ago

4.5.66

12 months ago

4.5.63

1 year ago

4.5.64

1 year ago

4.5.69

12 months ago

4.5.67

12 months ago

4.5.68

12 months ago

5.6.79

12 months ago

5.6.78

12 months ago

3.4.36

1 year ago

3.4.37

1 year ago

3.4.38

1 year ago

3.4.39

1 year ago

3.4.35

1 year ago

5.7.100

11 months ago

3.5.58

1 year ago

3.3.35

1 year ago

3.5.57

1 year ago

3.5.56

1 year ago

3.5.55

1 year ago

3.5.54

1 year ago

3.5.53

1 year ago

3.5.52

1 year ago

3.5.51

1 year ago

3.3.32

1 year ago

3.3.33

1 year ago

3.5.59

1 year ago

3.3.34

1 year ago

3.5.50

1 year ago

5.7.96

11 months ago

5.7.95

11 months ago

5.7.98

11 months ago

5.7.97

11 months ago

5.7.92

11 months ago

5.7.91

11 months ago

5.7.94

11 months ago

5.7.93

11 months ago

3.5.62

1 year ago

5.7.90

11 months ago

4.6.73

12 months ago

4.6.74

12 months ago

4.6.71

12 months ago

4.6.72

12 months ago

4.6.77

12 months ago

2.2.28

1 year ago

4.6.78

12 months ago

4.6.75

12 months ago

2.2.26

1 year ago

4.6.76

12 months ago

2.2.27

1 year ago

2.2.25

1 year ago

3.5.61

1 year ago

3.5.60

1 year ago

5.7.99

11 months ago

5.7.85

11 months ago

5.7.84

11 months ago

5.7.87

11 months ago

1.2.18

1 year ago

5.7.86

11 months ago

1.2.19

1 year ago

5.7.83

11 months ago

1.2.20

1 year ago

1.2.23

1 year ago

1.2.24

1 year ago

1.2.21

1 year ago

1.2.22

1 year ago

5.7.89

11 months ago

5.7.88

11 months ago

1.2.25

1 year ago

3.5.47

1 year ago

3.5.46

1 year ago

3.5.45

1 year ago

3.5.49

1 year ago

3.5.48

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

1.1.16

1 year ago

1.1.15

1 year ago

1.1.14

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago