@aligent/cdk-prerender-proxy 0.2.5-experimental2 → 0.2.5-experimental5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/lib/error-response-construct.js +1 -1
  2. package/lib/handlers/cache-control.ts +3 -20
  3. package/lib/handlers/error-response.ts +3 -50
  4. package/lib/handlers/package-lock.json +1257 -40
  5. package/lib/handlers/package.json +7 -3
  6. package/lib/handlers/prerender-check.ts +3 -26
  7. package/lib/handlers/prerender.ts +3 -42
  8. package/lib/handlers/tsconfig.json +1 -4
  9. package/lib/prerender-cf-cache-control-construct.js +1 -1
  10. package/lib/prerender-check-construct.js +1 -1
  11. package/lib/prerender-construct.js +1 -1
  12. package/package.json +6 -4
  13. package/lib/handlers/node_modules/.package-lock.json +0 -55
  14. package/lib/handlers/node_modules/@types/aws-lambda/LICENSE +0 -21
  15. package/lib/handlers/node_modules/@types/aws-lambda/README.md +0 -16
  16. package/lib/handlers/node_modules/@types/aws-lambda/common/api-gateway.d.ts +0 -79
  17. package/lib/handlers/node_modules/@types/aws-lambda/common/cloudfront.d.ts +0 -79
  18. package/lib/handlers/node_modules/@types/aws-lambda/handler.d.ts +0 -171
  19. package/lib/handlers/node_modules/@types/aws-lambda/index.d.ts +0 -85
  20. package/lib/handlers/node_modules/@types/aws-lambda/package.json +0 -210
  21. package/lib/handlers/node_modules/@types/aws-lambda/trigger/alb.d.ts +0 -48
  22. package/lib/handlers/node_modules/@types/aws-lambda/trigger/api-gateway-authorizer.d.ts +0 -174
  23. package/lib/handlers/node_modules/@types/aws-lambda/trigger/api-gateway-proxy.d.ts +0 -187
  24. package/lib/handlers/node_modules/@types/aws-lambda/trigger/appsync-resolver.d.ts +0 -51
  25. package/lib/handlers/node_modules/@types/aws-lambda/trigger/cloudformation-custom-resource.d.ts +0 -68
  26. package/lib/handlers/node_modules/@types/aws-lambda/trigger/cloudfront-request.d.ts +0 -20
  27. package/lib/handlers/node_modules/@types/aws-lambda/trigger/cloudfront-response.d.ts +0 -21
  28. package/lib/handlers/node_modules/@types/aws-lambda/trigger/cloudwatch-events.d.ts +0 -8
  29. package/lib/handlers/node_modules/@types/aws-lambda/trigger/cloudwatch-logs.d.ts +0 -37
  30. package/lib/handlers/node_modules/@types/aws-lambda/trigger/codebuild-cloudwatch-state.d.ts +0 -104
  31. package/lib/handlers/node_modules/@types/aws-lambda/trigger/codepipeline-cloudwatch-action.d.ts +0 -31
  32. package/lib/handlers/node_modules/@types/aws-lambda/trigger/codepipeline-cloudwatch-pipeline.d.ts +0 -32
  33. package/lib/handlers/node_modules/@types/aws-lambda/trigger/codepipeline-cloudwatch-stage.d.ts +0 -23
  34. package/lib/handlers/node_modules/@types/aws-lambda/trigger/codepipeline-cloudwatch.d.ts +0 -11
  35. package/lib/handlers/node_modules/@types/aws-lambda/trigger/codepipeline.d.ts +0 -55
  36. package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/_common.d.ts +0 -41
  37. package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/create-auth-challenge.d.ts +0 -22
  38. package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/custom-email-sender.d.ts +0 -86
  39. package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/custom-message.d.ts +0 -44
  40. package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/define-auth-challenge.d.ts +0 -21
  41. package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/index.d.ts +0 -119
  42. package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/post-authentication.d.ts +0 -15
  43. package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/post-confirmation.d.ts +0 -22
  44. package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/pre-authentication.d.ts +0 -15
  45. package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/pre-signup.d.ts +0 -31
  46. package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/pre-token-generation.d.ts +0 -45
  47. package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/user-migration.d.ts +0 -39
  48. package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/verify-auth-challenge-response.d.ts +0 -20
  49. package/lib/handlers/node_modules/@types/aws-lambda/trigger/connect-contact-flow.d.ts +0 -65
  50. package/lib/handlers/node_modules/@types/aws-lambda/trigger/dynamodb-stream.d.ts +0 -45
  51. package/lib/handlers/node_modules/@types/aws-lambda/trigger/eventbridge.d.ts +0 -18
  52. package/lib/handlers/node_modules/@types/aws-lambda/trigger/iot.d.ts +0 -28
  53. package/lib/handlers/node_modules/@types/aws-lambda/trigger/kinesis-firehose-transformation.d.ts +0 -45
  54. package/lib/handlers/node_modules/@types/aws-lambda/trigger/kinesis-stream.d.ts +0 -28
  55. package/lib/handlers/node_modules/@types/aws-lambda/trigger/lex.d.ts +0 -116
  56. package/lib/handlers/node_modules/@types/aws-lambda/trigger/msk.d.ts +0 -21
  57. package/lib/handlers/node_modules/@types/aws-lambda/trigger/s3-batch.d.ts +0 -41
  58. package/lib/handlers/node_modules/@types/aws-lambda/trigger/s3.d.ts +0 -60
  59. package/lib/handlers/node_modules/@types/aws-lambda/trigger/ses.d.ts +0 -103
  60. package/lib/handlers/node_modules/@types/aws-lambda/trigger/sns.d.ts +0 -38
  61. package/lib/handlers/node_modules/@types/aws-lambda/trigger/sqs.d.ts +0 -46
  62. package/lib/handlers/node_modules/@types/node/LICENSE +0 -21
  63. package/lib/handlers/node_modules/@types/node/README.md +0 -16
  64. package/lib/handlers/node_modules/@types/node/assert/strict.d.ts +0 -4
  65. package/lib/handlers/node_modules/@types/node/assert.d.ts +0 -124
  66. package/lib/handlers/node_modules/@types/node/async_hooks.d.ts +0 -226
  67. package/lib/handlers/node_modules/@types/node/base.d.ts +0 -19
  68. package/lib/handlers/node_modules/@types/node/buffer.d.ts +0 -84
  69. package/lib/handlers/node_modules/@types/node/child_process.d.ts +0 -526
  70. package/lib/handlers/node_modules/@types/node/cluster.d.ts +0 -262
  71. package/lib/handlers/node_modules/@types/node/console.d.ts +0 -133
  72. package/lib/handlers/node_modules/@types/node/constants.d.ts +0 -13
  73. package/lib/handlers/node_modules/@types/node/crypto.d.ts +0 -1580
  74. package/lib/handlers/node_modules/@types/node/dgram.d.ts +0 -141
  75. package/lib/handlers/node_modules/@types/node/diagnostic_channel.d.ts +0 -34
  76. package/lib/handlers/node_modules/@types/node/dns/promises.d.ts +0 -97
  77. package/lib/handlers/node_modules/@types/node/dns.d.ts +0 -322
  78. package/lib/handlers/node_modules/@types/node/domain.d.ts +0 -24
  79. package/lib/handlers/node_modules/@types/node/events.d.ts +0 -93
  80. package/lib/handlers/node_modules/@types/node/fs/promises.d.ts +0 -592
  81. package/lib/handlers/node_modules/@types/node/fs.d.ts +0 -2239
  82. package/lib/handlers/node_modules/@types/node/globals.d.ts +0 -655
  83. package/lib/handlers/node_modules/@types/node/globals.global.d.ts +0 -1
  84. package/lib/handlers/node_modules/@types/node/http.d.ts +0 -434
  85. package/lib/handlers/node_modules/@types/node/http2.d.ts +0 -976
  86. package/lib/handlers/node_modules/@types/node/https.d.ts +0 -36
  87. package/lib/handlers/node_modules/@types/node/index.d.ts +0 -58
  88. package/lib/handlers/node_modules/@types/node/inspector.d.ts +0 -3041
  89. package/lib/handlers/node_modules/@types/node/module.d.ts +0 -52
  90. package/lib/handlers/node_modules/@types/node/net.d.ts +0 -326
  91. package/lib/handlers/node_modules/@types/node/os.d.ts +0 -239
  92. package/lib/handlers/node_modules/@types/node/package.json +0 -232
  93. package/lib/handlers/node_modules/@types/node/path.d.ts +0 -163
  94. package/lib/handlers/node_modules/@types/node/perf_hooks.d.ts +0 -310
  95. package/lib/handlers/node_modules/@types/node/process.d.ts +0 -461
  96. package/lib/handlers/node_modules/@types/node/punycode.d.ts +0 -75
  97. package/lib/handlers/node_modules/@types/node/querystring.d.ts +0 -28
  98. package/lib/handlers/node_modules/@types/node/readline.d.ts +0 -192
  99. package/lib/handlers/node_modules/@types/node/repl.d.ts +0 -395
  100. package/lib/handlers/node_modules/@types/node/stream/promises.d.ts +0 -67
  101. package/lib/handlers/node_modules/@types/node/stream.d.ts +0 -471
  102. package/lib/handlers/node_modules/@types/node/string_decoder.d.ts +0 -7
  103. package/lib/handlers/node_modules/@types/node/timers/promises.d.ts +0 -21
  104. package/lib/handlers/node_modules/@types/node/timers.d.ts +0 -27
  105. package/lib/handlers/node_modules/@types/node/tls.d.ts +0 -793
  106. package/lib/handlers/node_modules/@types/node/trace_events.d.ts +0 -61
  107. package/lib/handlers/node_modules/@types/node/ts3.6/assert.d.ts +0 -98
  108. package/lib/handlers/node_modules/@types/node/ts3.6/base.d.ts +0 -68
  109. package/lib/handlers/node_modules/@types/node/ts3.6/index.d.ts +0 -7
  110. package/lib/handlers/node_modules/@types/node/tty.d.ts +0 -66
  111. package/lib/handlers/node_modules/@types/node/url.d.ts +0 -116
  112. package/lib/handlers/node_modules/@types/node/util/types.d.ts +0 -53
  113. package/lib/handlers/node_modules/@types/node/util.d.ts +0 -156
  114. package/lib/handlers/node_modules/@types/node/v8.d.ts +0 -198
  115. package/lib/handlers/node_modules/@types/node/vm.d.ts +0 -152
  116. package/lib/handlers/node_modules/@types/node/wasi.d.ts +0 -86
  117. package/lib/handlers/node_modules/@types/node/worker_threads.d.ts +0 -282
  118. package/lib/handlers/node_modules/@types/node/zlib.d.ts +0 -361
  119. package/lib/handlers/node_modules/axios/CHANGELOG.md +0 -685
  120. package/lib/handlers/node_modules/axios/LICENSE +0 -19
  121. package/lib/handlers/node_modules/axios/README.md +0 -800
  122. package/lib/handlers/node_modules/axios/UPGRADE_GUIDE.md +0 -162
  123. package/lib/handlers/node_modules/axios/dist/axios.js +0 -1756
  124. package/lib/handlers/node_modules/axios/dist/axios.map +0 -1
  125. package/lib/handlers/node_modules/axios/dist/axios.min.js +0 -3
  126. package/lib/handlers/node_modules/axios/dist/axios.min.map +0 -1
  127. package/lib/handlers/node_modules/axios/index.d.ts +0 -161
  128. package/lib/handlers/node_modules/axios/index.js +0 -1
  129. package/lib/handlers/node_modules/axios/lib/adapters/README.md +0 -37
  130. package/lib/handlers/node_modules/axios/lib/adapters/http.js +0 -303
  131. package/lib/handlers/node_modules/axios/lib/adapters/xhr.js +0 -179
  132. package/lib/handlers/node_modules/axios/lib/axios.js +0 -56
  133. package/lib/handlers/node_modules/axios/lib/cancel/Cancel.js +0 -19
  134. package/lib/handlers/node_modules/axios/lib/cancel/CancelToken.js +0 -57
  135. package/lib/handlers/node_modules/axios/lib/cancel/isCancel.js +0 -5
  136. package/lib/handlers/node_modules/axios/lib/core/Axios.js +0 -95
  137. package/lib/handlers/node_modules/axios/lib/core/InterceptorManager.js +0 -52
  138. package/lib/handlers/node_modules/axios/lib/core/README.md +0 -7
  139. package/lib/handlers/node_modules/axios/lib/core/buildFullPath.js +0 -20
  140. package/lib/handlers/node_modules/axios/lib/core/createError.js +0 -18
  141. package/lib/handlers/node_modules/axios/lib/core/dispatchRequest.js +0 -79
  142. package/lib/handlers/node_modules/axios/lib/core/enhanceError.js +0 -42
  143. package/lib/handlers/node_modules/axios/lib/core/mergeConfig.js +0 -87
  144. package/lib/handlers/node_modules/axios/lib/core/settle.js +0 -25
  145. package/lib/handlers/node_modules/axios/lib/core/transformData.js +0 -20
  146. package/lib/handlers/node_modules/axios/lib/defaults.js +0 -98
  147. package/lib/handlers/node_modules/axios/lib/helpers/README.md +0 -7
  148. package/lib/handlers/node_modules/axios/lib/helpers/bind.js +0 -11
  149. package/lib/handlers/node_modules/axios/lib/helpers/buildURL.js +0 -70
  150. package/lib/handlers/node_modules/axios/lib/helpers/combineURLs.js +0 -14
  151. package/lib/handlers/node_modules/axios/lib/helpers/cookies.js +0 -53
  152. package/lib/handlers/node_modules/axios/lib/helpers/deprecatedMethod.js +0 -24
  153. package/lib/handlers/node_modules/axios/lib/helpers/isAbsoluteURL.js +0 -14
  154. package/lib/handlers/node_modules/axios/lib/helpers/isAxiosError.js +0 -11
  155. package/lib/handlers/node_modules/axios/lib/helpers/isURLSameOrigin.js +0 -68
  156. package/lib/handlers/node_modules/axios/lib/helpers/normalizeHeaderName.js +0 -12
  157. package/lib/handlers/node_modules/axios/lib/helpers/parseHeaders.js +0 -53
  158. package/lib/handlers/node_modules/axios/lib/helpers/spread.js +0 -27
  159. package/lib/handlers/node_modules/axios/lib/utils.js +0 -351
  160. package/lib/handlers/node_modules/axios/package.json +0 -86
  161. package/lib/handlers/node_modules/buffer-from/LICENSE +0 -21
  162. package/lib/handlers/node_modules/buffer-from/index.js +0 -69
  163. package/lib/handlers/node_modules/buffer-from/package.json +0 -19
  164. package/lib/handlers/node_modules/buffer-from/readme.md +0 -69
  165. package/lib/handlers/node_modules/follow-redirects/LICENSE +0 -18
  166. package/lib/handlers/node_modules/follow-redirects/README.md +0 -148
  167. package/lib/handlers/node_modules/follow-redirects/debug.js +0 -14
  168. package/lib/handlers/node_modules/follow-redirects/http.js +0 -1
  169. package/lib/handlers/node_modules/follow-redirects/https.js +0 -1
  170. package/lib/handlers/node_modules/follow-redirects/index.js +0 -531
  171. package/lib/handlers/node_modules/follow-redirects/package.json +0 -59
  172. package/lib/handlers/node_modules/source-map/CHANGELOG.md +0 -301
  173. package/lib/handlers/node_modules/source-map/LICENSE +0 -28
  174. package/lib/handlers/node_modules/source-map/README.md +0 -742
  175. package/lib/handlers/node_modules/source-map/dist/source-map.debug.js +0 -3234
  176. package/lib/handlers/node_modules/source-map/dist/source-map.js +0 -3233
  177. package/lib/handlers/node_modules/source-map/dist/source-map.min.js +0 -2
  178. package/lib/handlers/node_modules/source-map/dist/source-map.min.js.map +0 -1
  179. package/lib/handlers/node_modules/source-map/lib/array-set.js +0 -121
  180. package/lib/handlers/node_modules/source-map/lib/base64-vlq.js +0 -140
  181. package/lib/handlers/node_modules/source-map/lib/base64.js +0 -67
  182. package/lib/handlers/node_modules/source-map/lib/binary-search.js +0 -111
  183. package/lib/handlers/node_modules/source-map/lib/mapping-list.js +0 -79
  184. package/lib/handlers/node_modules/source-map/lib/quick-sort.js +0 -114
  185. package/lib/handlers/node_modules/source-map/lib/source-map-consumer.js +0 -1145
  186. package/lib/handlers/node_modules/source-map/lib/source-map-generator.js +0 -425
  187. package/lib/handlers/node_modules/source-map/lib/source-node.js +0 -413
  188. package/lib/handlers/node_modules/source-map/lib/util.js +0 -488
  189. package/lib/handlers/node_modules/source-map/package.json +0 -73
  190. package/lib/handlers/node_modules/source-map/source-map.d.ts +0 -98
  191. package/lib/handlers/node_modules/source-map/source-map.js +0 -8
  192. package/lib/handlers/node_modules/source-map-support/LICENSE.md +0 -21
  193. package/lib/handlers/node_modules/source-map-support/README.md +0 -284
  194. package/lib/handlers/node_modules/source-map-support/browser-source-map-support.js +0 -114
  195. package/lib/handlers/node_modules/source-map-support/package.json +0 -31
  196. package/lib/handlers/node_modules/source-map-support/register.js +0 -1
  197. package/lib/handlers/node_modules/source-map-support/source-map-support.js +0 -604
@@ -1,148 +0,0 @@
1
- ## Follow Redirects
2
-
3
- Drop-in replacement for Node's `http` and `https` modules that automatically follows redirects.
4
-
5
- [![npm version](https://img.shields.io/npm/v/follow-redirects.svg)](https://www.npmjs.com/package/follow-redirects)
6
- [![Build Status](https://github.com/follow-redirects/follow-redirects/workflows/CI/badge.svg)](https://github.com/follow-redirects/follow-redirects/actions)
7
- [![Coverage Status](https://coveralls.io/repos/follow-redirects/follow-redirects/badge.svg?branch=master)](https://coveralls.io/r/follow-redirects/follow-redirects?branch=master)
8
- [![npm downloads](https://img.shields.io/npm/dm/follow-redirects.svg)](https://www.npmjs.com/package/follow-redirects)
9
- [![Sponsor on GitHub](https://img.shields.io/static/v1?label=Sponsor&message=%F0%9F%92%96&logo=GitHub)](https://github.com/sponsors/RubenVerborgh)
10
-
11
- `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)
12
- 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)
13
- modules, with the exception that they will seamlessly follow redirects.
14
-
15
- ```javascript
16
- const { http, https } = require('follow-redirects');
17
-
18
- http.get('http://bit.ly/900913', response => {
19
- response.on('data', chunk => {
20
- console.log(chunk);
21
- });
22
- }).on('error', err => {
23
- console.error(err);
24
- });
25
- ```
26
-
27
- You can inspect the final redirected URL through the `responseUrl` property on the `response`.
28
- If no redirection happened, `responseUrl` is the original request URL.
29
-
30
- ```javascript
31
- const request = https.request({
32
- host: 'bitly.com',
33
- path: '/UHfDGO',
34
- }, response => {
35
- console.log(response.responseUrl);
36
- // 'http://duckduckgo.com/robots.txt'
37
- });
38
- request.end();
39
- ```
40
-
41
- ## Options
42
- ### Global options
43
- Global options are set directly on the `follow-redirects` module:
44
-
45
- ```javascript
46
- const followRedirects = require('follow-redirects');
47
- followRedirects.maxRedirects = 10;
48
- followRedirects.maxBodyLength = 20 * 1024 * 1024; // 20 MB
49
- ```
50
-
51
- The following global options are supported:
52
-
53
- - `maxRedirects` (default: `21`) – sets the maximum number of allowed redirects; if exceeded, an error will be emitted.
54
-
55
- - `maxBodyLength` (default: 10MB) – sets the maximum size of the request body; if exceeded, an error will be emitted.
56
-
57
- ### Per-request options
58
- Per-request options are set by passing an `options` object:
59
-
60
- ```javascript
61
- const url = require('url');
62
- const { http, https } = require('follow-redirects');
63
-
64
- const options = url.parse('http://bit.ly/900913');
65
- options.maxRedirects = 10;
66
- options.beforeRedirect = (options, { headers }) => {
67
- // Use this to adjust the request options upon redirecting,
68
- // to inspect the latest response headers,
69
- // or to cancel the request by throwing an error
70
- if (options.hostname === "example.com") {
71
- options.auth = "user:password";
72
- }
73
- };
74
- http.request(options);
75
- ```
76
-
77
- 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),
78
- the following per-request options are supported:
79
- - `followRedirects` (default: `true`) – whether redirects should be followed.
80
-
81
- - `maxRedirects` (default: `21`) – sets the maximum number of allowed redirects; if exceeded, an error will be emitted.
82
-
83
- - `maxBodyLength` (default: 10MB) – sets the maximum size of the request body; if exceeded, an error will be emitted.
84
-
85
- - `beforeRedirect` (default: `undefined`) – optionally change the request `options` on redirects, or abort the request by throwing an error.
86
-
87
- - `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() }`
88
-
89
- - `trackRedirects` (default: `false`) – whether to store the redirected response details into the `redirects` array on the response object.
90
-
91
-
92
- ### Advanced usage
93
- By default, `follow-redirects` will use the Node.js default implementations
94
- of [`http`](https://nodejs.org/api/http.html)
95
- and [`https`](https://nodejs.org/api/https.html).
96
- To enable features such as caching and/or intermediate request tracking,
97
- you might instead want to wrap `follow-redirects` around custom protocol implementations:
98
-
99
- ```javascript
100
- const { http, https } = require('follow-redirects').wrap({
101
- http: require('your-custom-http'),
102
- https: require('your-custom-https'),
103
- });
104
- ```
105
-
106
- Such custom protocols only need an implementation of the `request` method.
107
-
108
- ## Browser Usage
109
-
110
- Due to the way the browser works,
111
- the `http` and `https` browser equivalents perform redirects by default.
112
-
113
- By requiring `follow-redirects` this way:
114
- ```javascript
115
- const http = require('follow-redirects/http');
116
- const https = require('follow-redirects/https');
117
- ```
118
- you can easily tell webpack and friends to replace
119
- `follow-redirect` by the built-in versions:
120
-
121
- ```json
122
- {
123
- "follow-redirects/http" : "http",
124
- "follow-redirects/https" : "https"
125
- }
126
- ```
127
-
128
- ## Contributing
129
-
130
- Pull Requests are always welcome. Please [file an issue](https://github.com/follow-redirects/follow-redirects/issues)
131
- detailing your proposal before you invest your valuable time. Additional features and bug fixes should be accompanied
132
- by tests. You can run the test suite locally with a simple `npm test` command.
133
-
134
- ## Debug Logging
135
-
136
- `follow-redirects` uses the excellent [debug](https://www.npmjs.com/package/debug) for logging. To turn on logging
137
- set the environment variable `DEBUG=follow-redirects` for debug output from just this module. When running the test
138
- suite it is sometimes advantageous to set `DEBUG=*` to see output from the express server as well.
139
-
140
- ## Authors
141
-
142
- - [Ruben Verborgh](https://ruben.verborgh.org/)
143
- - [Olivier Lalonde](mailto:olalonde@gmail.com)
144
- - [James Talmage](mailto:james@talmage.io)
145
-
146
- ## License
147
-
148
- [MIT License](https://github.com/follow-redirects/follow-redirects/blob/master/LICENSE)
@@ -1,14 +0,0 @@
1
- var debug;
2
-
3
- module.exports = function () {
4
- if (!debug) {
5
- try {
6
- /* eslint global-require: off */
7
- debug = require("debug")("follow-redirects");
8
- }
9
- catch (error) {
10
- debug = function () { /* */ };
11
- }
12
- }
13
- debug.apply(null, arguments);
14
- };
@@ -1 +0,0 @@
1
- module.exports = require("./").http;
@@ -1 +0,0 @@
1
- module.exports = require("./").https;
@@ -1,531 +0,0 @@
1
- var url = require("url");
2
- var URL = url.URL;
3
- var http = require("http");
4
- var https = require("https");
5
- var Writable = require("stream").Writable;
6
- var assert = require("assert");
7
- var debug = require("./debug");
8
-
9
- // Create handlers that pass events from native requests
10
- var events = ["abort", "aborted", "connect", "error", "socket", "timeout"];
11
- var eventHandlers = Object.create(null);
12
- events.forEach(function (event) {
13
- eventHandlers[event] = function (arg1, arg2, arg3) {
14
- this._redirectable.emit(event, arg1, arg2, arg3);
15
- };
16
- });
17
-
18
- // Error types with codes
19
- var RedirectionError = createErrorType(
20
- "ERR_FR_REDIRECTION_FAILURE",
21
- ""
22
- );
23
- var TooManyRedirectsError = createErrorType(
24
- "ERR_FR_TOO_MANY_REDIRECTS",
25
- "Maximum number of redirects exceeded"
26
- );
27
- var MaxBodyLengthExceededError = createErrorType(
28
- "ERR_FR_MAX_BODY_LENGTH_EXCEEDED",
29
- "Request body larger than maxBodyLength limit"
30
- );
31
- var WriteAfterEndError = createErrorType(
32
- "ERR_STREAM_WRITE_AFTER_END",
33
- "write after end"
34
- );
35
-
36
- // An HTTP(S) request that can be redirected
37
- function RedirectableRequest(options, responseCallback) {
38
- // Initialize the request
39
- Writable.call(this);
40
- this._sanitizeOptions(options);
41
- this._options = options;
42
- this._ended = false;
43
- this._ending = false;
44
- this._redirectCount = 0;
45
- this._redirects = [];
46
- this._requestBodyLength = 0;
47
- this._requestBodyBuffers = [];
48
-
49
- // Attach a callback if passed
50
- if (responseCallback) {
51
- this.on("response", responseCallback);
52
- }
53
-
54
- // React to responses of native requests
55
- var self = this;
56
- this._onNativeResponse = function (response) {
57
- self._processResponse(response);
58
- };
59
-
60
- // Perform the first request
61
- this._performRequest();
62
- }
63
- RedirectableRequest.prototype = Object.create(Writable.prototype);
64
-
65
- RedirectableRequest.prototype.abort = function () {
66
- abortRequest(this._currentRequest);
67
- this.emit("abort");
68
- };
69
-
70
- // Writes buffered data to the current native request
71
- RedirectableRequest.prototype.write = function (data, encoding, callback) {
72
- // Writing is not allowed if end has been called
73
- if (this._ending) {
74
- throw new WriteAfterEndError();
75
- }
76
-
77
- // Validate input and shift parameters if necessary
78
- if (!(typeof data === "string" || typeof data === "object" && ("length" in data))) {
79
- throw new TypeError("data should be a string, Buffer or Uint8Array");
80
- }
81
- if (typeof encoding === "function") {
82
- callback = encoding;
83
- encoding = null;
84
- }
85
-
86
- // Ignore empty buffers, since writing them doesn't invoke the callback
87
- // https://github.com/nodejs/node/issues/22066
88
- if (data.length === 0) {
89
- if (callback) {
90
- callback();
91
- }
92
- return;
93
- }
94
- // Only write when we don't exceed the maximum body length
95
- if (this._requestBodyLength + data.length <= this._options.maxBodyLength) {
96
- this._requestBodyLength += data.length;
97
- this._requestBodyBuffers.push({ data: data, encoding: encoding });
98
- this._currentRequest.write(data, encoding, callback);
99
- }
100
- // Error when we exceed the maximum body length
101
- else {
102
- this.emit("error", new MaxBodyLengthExceededError());
103
- this.abort();
104
- }
105
- };
106
-
107
- // Ends the current native request
108
- RedirectableRequest.prototype.end = function (data, encoding, callback) {
109
- // Shift parameters if necessary
110
- if (typeof data === "function") {
111
- callback = data;
112
- data = encoding = null;
113
- }
114
- else if (typeof encoding === "function") {
115
- callback = encoding;
116
- encoding = null;
117
- }
118
-
119
- // Write data if needed and end
120
- if (!data) {
121
- this._ended = this._ending = true;
122
- this._currentRequest.end(null, null, callback);
123
- }
124
- else {
125
- var self = this;
126
- var currentRequest = this._currentRequest;
127
- this.write(data, encoding, function () {
128
- self._ended = true;
129
- currentRequest.end(null, null, callback);
130
- });
131
- this._ending = true;
132
- }
133
- };
134
-
135
- // Sets a header value on the current native request
136
- RedirectableRequest.prototype.setHeader = function (name, value) {
137
- this._options.headers[name] = value;
138
- this._currentRequest.setHeader(name, value);
139
- };
140
-
141
- // Clears a header value on the current native request
142
- RedirectableRequest.prototype.removeHeader = function (name) {
143
- delete this._options.headers[name];
144
- this._currentRequest.removeHeader(name);
145
- };
146
-
147
- // Global timeout for all underlying requests
148
- RedirectableRequest.prototype.setTimeout = function (msecs, callback) {
149
- var self = this;
150
- if (callback) {
151
- this.on("timeout", callback);
152
- }
153
-
154
- function destroyOnTimeout(socket) {
155
- socket.setTimeout(msecs);
156
- socket.removeListener("timeout", socket.destroy);
157
- socket.addListener("timeout", socket.destroy);
158
- }
159
-
160
- // Sets up a timer to trigger a timeout event
161
- function startTimer(socket) {
162
- if (self._timeout) {
163
- clearTimeout(self._timeout);
164
- }
165
- self._timeout = setTimeout(function () {
166
- self.emit("timeout");
167
- clearTimer();
168
- }, msecs);
169
- destroyOnTimeout(socket);
170
- }
171
-
172
- // Prevent a timeout from triggering
173
- function clearTimer() {
174
- clearTimeout(this._timeout);
175
- if (callback) {
176
- self.removeListener("timeout", callback);
177
- }
178
- if (!this.socket) {
179
- self._currentRequest.removeListener("socket", startTimer);
180
- }
181
- }
182
-
183
- // Start the timer when the socket is opened
184
- if (this.socket) {
185
- startTimer(this.socket);
186
- }
187
- else {
188
- this._currentRequest.once("socket", startTimer);
189
- }
190
-
191
- this.on("socket", destroyOnTimeout);
192
- this.once("response", clearTimer);
193
- this.once("error", clearTimer);
194
-
195
- return this;
196
- };
197
-
198
- // Proxy all other public ClientRequest methods
199
- [
200
- "flushHeaders", "getHeader",
201
- "setNoDelay", "setSocketKeepAlive",
202
- ].forEach(function (method) {
203
- RedirectableRequest.prototype[method] = function (a, b) {
204
- return this._currentRequest[method](a, b);
205
- };
206
- });
207
-
208
- // Proxy all public ClientRequest properties
209
- ["aborted", "connection", "socket"].forEach(function (property) {
210
- Object.defineProperty(RedirectableRequest.prototype, property, {
211
- get: function () { return this._currentRequest[property]; },
212
- });
213
- });
214
-
215
- RedirectableRequest.prototype._sanitizeOptions = function (options) {
216
- // Ensure headers are always present
217
- if (!options.headers) {
218
- options.headers = {};
219
- }
220
-
221
- // Since http.request treats host as an alias of hostname,
222
- // but the url module interprets host as hostname plus port,
223
- // eliminate the host property to avoid confusion.
224
- if (options.host) {
225
- // Use hostname if set, because it has precedence
226
- if (!options.hostname) {
227
- options.hostname = options.host;
228
- }
229
- delete options.host;
230
- }
231
-
232
- // Complete the URL object when necessary
233
- if (!options.pathname && options.path) {
234
- var searchPos = options.path.indexOf("?");
235
- if (searchPos < 0) {
236
- options.pathname = options.path;
237
- }
238
- else {
239
- options.pathname = options.path.substring(0, searchPos);
240
- options.search = options.path.substring(searchPos);
241
- }
242
- }
243
- };
244
-
245
-
246
- // Executes the next native request (initial or redirect)
247
- RedirectableRequest.prototype._performRequest = function () {
248
- // Load the native protocol
249
- var protocol = this._options.protocol;
250
- var nativeProtocol = this._options.nativeProtocols[protocol];
251
- if (!nativeProtocol) {
252
- this.emit("error", new TypeError("Unsupported protocol " + protocol));
253
- return;
254
- }
255
-
256
- // If specified, use the agent corresponding to the protocol
257
- // (HTTP and HTTPS use different types of agents)
258
- if (this._options.agents) {
259
- var scheme = protocol.substr(0, protocol.length - 1);
260
- this._options.agent = this._options.agents[scheme];
261
- }
262
-
263
- // Create the native request
264
- var request = this._currentRequest =
265
- nativeProtocol.request(this._options, this._onNativeResponse);
266
- this._currentUrl = url.format(this._options);
267
-
268
- // Set up event handlers
269
- request._redirectable = this;
270
- for (var e = 0; e < events.length; e++) {
271
- request.on(events[e], eventHandlers[events[e]]);
272
- }
273
-
274
- // End a redirected request
275
- // (The first request must be ended explicitly with RedirectableRequest#end)
276
- if (this._isRedirect) {
277
- // Write the request entity and end.
278
- var i = 0;
279
- var self = this;
280
- var buffers = this._requestBodyBuffers;
281
- (function writeNext(error) {
282
- // Only write if this request has not been redirected yet
283
- /* istanbul ignore else */
284
- if (request === self._currentRequest) {
285
- // Report any write errors
286
- /* istanbul ignore if */
287
- if (error) {
288
- self.emit("error", error);
289
- }
290
- // Write the next buffer if there are still left
291
- else if (i < buffers.length) {
292
- var buffer = buffers[i++];
293
- /* istanbul ignore else */
294
- if (!request.finished) {
295
- request.write(buffer.data, buffer.encoding, writeNext);
296
- }
297
- }
298
- // End the request if `end` has been called on us
299
- else if (self._ended) {
300
- request.end();
301
- }
302
- }
303
- }());
304
- }
305
- };
306
-
307
- // Processes a response from the current native request
308
- RedirectableRequest.prototype._processResponse = function (response) {
309
- // Store the redirected response
310
- var statusCode = response.statusCode;
311
- if (this._options.trackRedirects) {
312
- this._redirects.push({
313
- url: this._currentUrl,
314
- headers: response.headers,
315
- statusCode: statusCode,
316
- });
317
- }
318
-
319
- // RFC7231§6.4: The 3xx (Redirection) class of status code indicates
320
- // that further action needs to be taken by the user agent in order to
321
- // fulfill the request. If a Location header field is provided,
322
- // the user agent MAY automatically redirect its request to the URI
323
- // referenced by the Location field value,
324
- // even if the specific status code is not understood.
325
- var location = response.headers.location;
326
- if (location && this._options.followRedirects !== false &&
327
- statusCode >= 300 && statusCode < 400) {
328
- // Abort the current request
329
- abortRequest(this._currentRequest);
330
- // Discard the remainder of the response to avoid waiting for data
331
- response.destroy();
332
-
333
- // RFC7231§6.4: A client SHOULD detect and intervene
334
- // in cyclical redirections (i.e., "infinite" redirection loops).
335
- if (++this._redirectCount > this._options.maxRedirects) {
336
- this.emit("error", new TooManyRedirectsError());
337
- return;
338
- }
339
-
340
- // RFC7231§6.4: Automatic redirection needs to done with
341
- // care for methods not known to be safe, […]
342
- // RFC7231§6.4.2–3: For historical reasons, a user agent MAY change
343
- // the request method from POST to GET for the subsequent request.
344
- if ((statusCode === 301 || statusCode === 302) && this._options.method === "POST" ||
345
- // RFC7231§6.4.4: The 303 (See Other) status code indicates that
346
- // the server is redirecting the user agent to a different resource […]
347
- // A user agent can perform a retrieval request targeting that URI
348
- // (a GET or HEAD request if using HTTP) […]
349
- (statusCode === 303) && !/^(?:GET|HEAD)$/.test(this._options.method)) {
350
- this._options.method = "GET";
351
- // Drop a possible entity and headers related to it
352
- this._requestBodyBuffers = [];
353
- removeMatchingHeaders(/^content-/i, this._options.headers);
354
- }
355
-
356
- // Drop the Host header, as the redirect might lead to a different host
357
- var previousHostName = removeMatchingHeaders(/^host$/i, this._options.headers) ||
358
- url.parse(this._currentUrl).hostname;
359
-
360
- // Create the redirected request
361
- var redirectUrl = url.resolve(this._currentUrl, location);
362
- debug("redirecting to", redirectUrl);
363
- this._isRedirect = true;
364
- var redirectUrlParts = url.parse(redirectUrl);
365
- Object.assign(this._options, redirectUrlParts);
366
-
367
- // Drop the Authorization header if redirecting to another host
368
- if (redirectUrlParts.hostname !== previousHostName) {
369
- removeMatchingHeaders(/^authorization$/i, this._options.headers);
370
- }
371
-
372
- // Evaluate the beforeRedirect callback
373
- if (typeof this._options.beforeRedirect === "function") {
374
- var responseDetails = { headers: response.headers };
375
- try {
376
- this._options.beforeRedirect.call(null, this._options, responseDetails);
377
- }
378
- catch (err) {
379
- this.emit("error", err);
380
- return;
381
- }
382
- this._sanitizeOptions(this._options);
383
- }
384
-
385
- // Perform the redirected request
386
- try {
387
- this._performRequest();
388
- }
389
- catch (cause) {
390
- var error = new RedirectionError("Redirected request failed: " + cause.message);
391
- error.cause = cause;
392
- this.emit("error", error);
393
- }
394
- }
395
- else {
396
- // The response is not a redirect; return it as-is
397
- response.responseUrl = this._currentUrl;
398
- response.redirects = this._redirects;
399
- this.emit("response", response);
400
-
401
- // Clean up
402
- this._requestBodyBuffers = [];
403
- }
404
- };
405
-
406
- // Wraps the key/value object of protocols with redirect functionality
407
- function wrap(protocols) {
408
- // Default settings
409
- var exports = {
410
- maxRedirects: 21,
411
- maxBodyLength: 10 * 1024 * 1024,
412
- };
413
-
414
- // Wrap each protocol
415
- var nativeProtocols = {};
416
- Object.keys(protocols).forEach(function (scheme) {
417
- var protocol = scheme + ":";
418
- var nativeProtocol = nativeProtocols[protocol] = protocols[scheme];
419
- var wrappedProtocol = exports[scheme] = Object.create(nativeProtocol);
420
-
421
- // Executes a request, following redirects
422
- function request(input, options, callback) {
423
- // Parse parameters
424
- if (typeof input === "string") {
425
- var urlStr = input;
426
- try {
427
- input = urlToOptions(new URL(urlStr));
428
- }
429
- catch (err) {
430
- /* istanbul ignore next */
431
- input = url.parse(urlStr);
432
- }
433
- }
434
- else if (URL && (input instanceof URL)) {
435
- input = urlToOptions(input);
436
- }
437
- else {
438
- callback = options;
439
- options = input;
440
- input = { protocol: protocol };
441
- }
442
- if (typeof options === "function") {
443
- callback = options;
444
- options = null;
445
- }
446
-
447
- // Set defaults
448
- options = Object.assign({
449
- maxRedirects: exports.maxRedirects,
450
- maxBodyLength: exports.maxBodyLength,
451
- }, input, options);
452
- options.nativeProtocols = nativeProtocols;
453
-
454
- assert.equal(options.protocol, protocol, "protocol mismatch");
455
- debug("options", options);
456
- return new RedirectableRequest(options, callback);
457
- }
458
-
459
- // Executes a GET request, following redirects
460
- function get(input, options, callback) {
461
- var wrappedRequest = wrappedProtocol.request(input, options, callback);
462
- wrappedRequest.end();
463
- return wrappedRequest;
464
- }
465
-
466
- // Expose the properties on the wrapped protocol
467
- Object.defineProperties(wrappedProtocol, {
468
- request: { value: request, configurable: true, enumerable: true, writable: true },
469
- get: { value: get, configurable: true, enumerable: true, writable: true },
470
- });
471
- });
472
- return exports;
473
- }
474
-
475
- /* istanbul ignore next */
476
- function noop() { /* empty */ }
477
-
478
- // from https://github.com/nodejs/node/blob/master/lib/internal/url.js
479
- function urlToOptions(urlObject) {
480
- var options = {
481
- protocol: urlObject.protocol,
482
- hostname: urlObject.hostname.startsWith("[") ?
483
- /* istanbul ignore next */
484
- urlObject.hostname.slice(1, -1) :
485
- urlObject.hostname,
486
- hash: urlObject.hash,
487
- search: urlObject.search,
488
- pathname: urlObject.pathname,
489
- path: urlObject.pathname + urlObject.search,
490
- href: urlObject.href,
491
- };
492
- if (urlObject.port !== "") {
493
- options.port = Number(urlObject.port);
494
- }
495
- return options;
496
- }
497
-
498
- function removeMatchingHeaders(regex, headers) {
499
- var lastValue;
500
- for (var header in headers) {
501
- if (regex.test(header)) {
502
- lastValue = headers[header];
503
- delete headers[header];
504
- }
505
- }
506
- return lastValue;
507
- }
508
-
509
- function createErrorType(code, defaultMessage) {
510
- function CustomError(message) {
511
- Error.captureStackTrace(this, this.constructor);
512
- this.message = message || defaultMessage;
513
- }
514
- CustomError.prototype = new Error();
515
- CustomError.prototype.constructor = CustomError;
516
- CustomError.prototype.name = "Error [" + code + "]";
517
- CustomError.prototype.code = code;
518
- return CustomError;
519
- }
520
-
521
- function abortRequest(request) {
522
- for (var e = 0; e < events.length; e++) {
523
- request.removeListener(events[e], eventHandlers[events[e]]);
524
- }
525
- request.on("error", noop);
526
- request.abort();
527
- }
528
-
529
- // Exports
530
- module.exports = wrap({ http: http, https: https });
531
- module.exports.wrap = wrap;