@recode-js/next-toolkit 0.0.1

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 (266) hide show
  1. package/README.md +27 -0
  2. package/dist/NextToolkitProvider.d.ts +8 -0
  3. package/dist/NextToolkitProvider.d.ts.map +1 -0
  4. package/dist/NextToolkitProvider.js +12 -0
  5. package/dist/NextToolkitProvider.js.map +1 -0
  6. package/dist/_virtual/_commonjsHelpers.js +6 -0
  7. package/dist/_virtual/_commonjsHelpers.js.map +1 -0
  8. package/dist/_virtual/browser.js +4 -0
  9. package/dist/_virtual/browser.js.map +1 -0
  10. package/dist/_virtual/index.js +4 -0
  11. package/dist/_virtual/index.js.map +1 -0
  12. package/dist/_virtual/index2.js +4 -0
  13. package/dist/_virtual/index2.js.map +1 -0
  14. package/dist/_virtual/index3.js +4 -0
  15. package/dist/_virtual/index3.js.map +1 -0
  16. package/dist/_virtual/node.js +4 -0
  17. package/dist/_virtual/node.js.map +1 -0
  18. package/dist/_virtual/use-sync-external-store-with-selector.development.js +4 -0
  19. package/dist/_virtual/use-sync-external-store-with-selector.development.js.map +1 -0
  20. package/dist/_virtual/use-sync-external-store-with-selector.production.js +4 -0
  21. package/dist/_virtual/use-sync-external-store-with-selector.production.js.map +1 -0
  22. package/dist/_virtual/with-selector.js +4 -0
  23. package/dist/_virtual/with-selector.js.map +1 -0
  24. package/dist/axios/api.d.ts +16 -0
  25. package/dist/axios/api.d.ts.map +1 -0
  26. package/dist/axios/api.js +11 -0
  27. package/dist/axios/api.js.map +1 -0
  28. package/dist/components/auth/Form.d.ts +10 -0
  29. package/dist/components/auth/Form.d.ts.map +1 -0
  30. package/dist/components/auth/Form.js +49 -0
  31. package/dist/components/auth/Form.js.map +1 -0
  32. package/dist/components/auth/auth.d.ts +8 -0
  33. package/dist/components/auth/auth.d.ts.map +1 -0
  34. package/dist/components/auth/auth.js +18 -0
  35. package/dist/components/auth/auth.js.map +1 -0
  36. package/dist/components/auth/formActions.d.ts +17 -0
  37. package/dist/components/auth/formActions.d.ts.map +1 -0
  38. package/dist/components/auth/formActions.js +58 -0
  39. package/dist/components/auth/formActions.js.map +1 -0
  40. package/dist/components/auth/login/LoginPage.d.ts +7 -0
  41. package/dist/components/auth/login/LoginPage.d.ts.map +1 -0
  42. package/dist/components/auth/login/LoginPage.js +18 -0
  43. package/dist/components/auth/login/LoginPage.js.map +1 -0
  44. package/dist/components/auth/login/login.d.ts +1 -0
  45. package/dist/components/auth/login/login.d.ts.map +1 -0
  46. package/dist/components/auth/register/RegisterPage.d.ts +7 -0
  47. package/dist/components/auth/register/RegisterPage.d.ts.map +1 -0
  48. package/dist/components/auth/register/RegisterPage.js +18 -0
  49. package/dist/components/auth/register/RegisterPage.js.map +1 -0
  50. package/dist/components/auth/register/register.d.ts +1 -0
  51. package/dist/components/auth/register/register.d.ts.map +1 -0
  52. package/dist/components/auth/styles/form.module.css.js +4 -0
  53. package/dist/components/auth/styles/form.module.css.js.map +1 -0
  54. package/dist/components/common/Button.d.ts +25 -0
  55. package/dist/components/common/Button.d.ts.map +1 -0
  56. package/dist/components/common/Button.js +25 -0
  57. package/dist/components/common/Button.js.map +1 -0
  58. package/dist/components/common/styles/button.module.css.js +4 -0
  59. package/dist/components/common/styles/button.module.css.js.map +1 -0
  60. package/dist/components/navigation/NavigatorProvider.d.ts +10 -0
  61. package/dist/components/navigation/NavigatorProvider.d.ts.map +1 -0
  62. package/dist/components/navigation/NavigatorProvider.js +15 -0
  63. package/dist/components/navigation/NavigatorProvider.js.map +1 -0
  64. package/dist/components/navigation/bottom-tab/BottomTab.d.ts +12 -0
  65. package/dist/components/navigation/bottom-tab/BottomTab.d.ts.map +1 -0
  66. package/dist/components/navigation/bottom-tab/BottomTab.js +45 -0
  67. package/dist/components/navigation/bottom-tab/BottomTab.js.map +1 -0
  68. package/dist/components/navigation/bottom-tab/bottom-tab.module.css.js +4 -0
  69. package/dist/components/navigation/bottom-tab/bottom-tab.module.css.js.map +1 -0
  70. package/dist/components/navigation/drawer/Drawer.d.ts +21 -0
  71. package/dist/components/navigation/drawer/Drawer.d.ts.map +1 -0
  72. package/dist/components/navigation/drawer/Drawer.js +91 -0
  73. package/dist/components/navigation/drawer/Drawer.js.map +1 -0
  74. package/dist/components/navigation/drawer/drawer.module.css.js +4 -0
  75. package/dist/components/navigation/drawer/drawer.module.css.js.map +1 -0
  76. package/dist/components/navigation/header/Header.d.ts +7 -0
  77. package/dist/components/navigation/header/Header.d.ts.map +1 -0
  78. package/dist/components/navigation/header/Header.js +32 -0
  79. package/dist/components/navigation/header/Header.js.map +1 -0
  80. package/dist/components/navigation/header/header.module.css.js +4 -0
  81. package/dist/components/navigation/header/header.module.css.js.map +1 -0
  82. package/dist/components/navigation/navigatior-provider.module.css.js +4 -0
  83. package/dist/components/navigation/navigatior-provider.module.css.js.map +1 -0
  84. package/dist/components/toast/Toast.d.ts +9 -0
  85. package/dist/components/toast/Toast.d.ts.map +1 -0
  86. package/dist/components/toast/Toast.js +92 -0
  87. package/dist/components/toast/Toast.js.map +1 -0
  88. package/dist/components/toast/ToastExamples.d.ts +2 -0
  89. package/dist/components/toast/ToastExamples.d.ts.map +1 -0
  90. package/dist/components/toast/ToastExamples.js +74 -0
  91. package/dist/components/toast/ToastExamples.js.map +1 -0
  92. package/dist/components/toast/toast.module.css.js +4 -0
  93. package/dist/components/toast/toast.module.css.js.map +1 -0
  94. package/dist/index.d.ts +11 -0
  95. package/dist/index.d.ts.map +1 -0
  96. package/dist/index.js +9 -0
  97. package/dist/index.js.map +1 -0
  98. package/dist/node_modules/@reduxjs/toolkit/dist/redux-toolkit.modern.js +969 -0
  99. package/dist/node_modules/@reduxjs/toolkit/dist/redux-toolkit.modern.js.map +1 -0
  100. package/dist/node_modules/axios/index.js +26 -0
  101. package/dist/node_modules/axios/index.js.map +1 -0
  102. package/dist/node_modules/axios/lib/adapters/adapters.js +129 -0
  103. package/dist/node_modules/axios/lib/adapters/adapters.js.map +1 -0
  104. package/dist/node_modules/axios/lib/adapters/fetch.js +289 -0
  105. package/dist/node_modules/axios/lib/adapters/fetch.js.map +1 -0
  106. package/dist/node_modules/axios/lib/adapters/http.js +895 -0
  107. package/dist/node_modules/axios/lib/adapters/http.js.map +1 -0
  108. package/dist/node_modules/axios/lib/adapters/xhr.js +203 -0
  109. package/dist/node_modules/axios/lib/adapters/xhr.js.map +1 -0
  110. package/dist/node_modules/axios/lib/axios.js +88 -0
  111. package/dist/node_modules/axios/lib/axios.js.map +1 -0
  112. package/dist/node_modules/axios/lib/cancel/CancelToken.js +135 -0
  113. package/dist/node_modules/axios/lib/cancel/CancelToken.js.map +1 -0
  114. package/dist/node_modules/axios/lib/cancel/CanceledError.js +25 -0
  115. package/dist/node_modules/axios/lib/cancel/CanceledError.js.map +1 -0
  116. package/dist/node_modules/axios/lib/cancel/isCancel.js +7 -0
  117. package/dist/node_modules/axios/lib/cancel/isCancel.js.map +1 -0
  118. package/dist/node_modules/axios/lib/core/Axios.js +238 -0
  119. package/dist/node_modules/axios/lib/core/Axios.js.map +1 -0
  120. package/dist/node_modules/axios/lib/core/AxiosError.js +110 -0
  121. package/dist/node_modules/axios/lib/core/AxiosError.js.map +1 -0
  122. package/dist/node_modules/axios/lib/core/AxiosHeaders.js +314 -0
  123. package/dist/node_modules/axios/lib/core/AxiosHeaders.js.map +1 -0
  124. package/dist/node_modules/axios/lib/core/InterceptorManager.js +71 -0
  125. package/dist/node_modules/axios/lib/core/InterceptorManager.js.map +1 -0
  126. package/dist/node_modules/axios/lib/core/buildFullPath.js +24 -0
  127. package/dist/node_modules/axios/lib/core/buildFullPath.js.map +1 -0
  128. package/dist/node_modules/axios/lib/core/dispatchRequest.js +83 -0
  129. package/dist/node_modules/axios/lib/core/dispatchRequest.js.map +1 -0
  130. package/dist/node_modules/axios/lib/core/mergeConfig.js +108 -0
  131. package/dist/node_modules/axios/lib/core/mergeConfig.js.map +1 -0
  132. package/dist/node_modules/axios/lib/core/settle.js +29 -0
  133. package/dist/node_modules/axios/lib/core/settle.js.map +1 -0
  134. package/dist/node_modules/axios/lib/core/transformData.js +30 -0
  135. package/dist/node_modules/axios/lib/core/transformData.js.map +1 -0
  136. package/dist/node_modules/axios/lib/defaults/index.js +161 -0
  137. package/dist/node_modules/axios/lib/defaults/index.js.map +1 -0
  138. package/dist/node_modules/axios/lib/defaults/transitional.js +9 -0
  139. package/dist/node_modules/axios/lib/defaults/transitional.js.map +1 -0
  140. package/dist/node_modules/axios/lib/env/data.js +4 -0
  141. package/dist/node_modules/axios/lib/env/data.js.map +1 -0
  142. package/dist/node_modules/axios/lib/helpers/AxiosTransformStream.js +143 -0
  143. package/dist/node_modules/axios/lib/helpers/AxiosTransformStream.js.map +1 -0
  144. package/dist/node_modules/axios/lib/helpers/AxiosURLSearchParams.js +58 -0
  145. package/dist/node_modules/axios/lib/helpers/AxiosURLSearchParams.js.map +1 -0
  146. package/dist/node_modules/axios/lib/helpers/HttpStatusCode.js +78 -0
  147. package/dist/node_modules/axios/lib/helpers/HttpStatusCode.js.map +1 -0
  148. package/dist/node_modules/axios/lib/helpers/ZlibHeaderTransformStream.js +28 -0
  149. package/dist/node_modules/axios/lib/helpers/ZlibHeaderTransformStream.js.map +1 -0
  150. package/dist/node_modules/axios/lib/helpers/bind.js +16 -0
  151. package/dist/node_modules/axios/lib/helpers/bind.js.map +1 -0
  152. package/dist/node_modules/axios/lib/helpers/buildURL.js +69 -0
  153. package/dist/node_modules/axios/lib/helpers/buildURL.js.map +1 -0
  154. package/dist/node_modules/axios/lib/helpers/callbackify.js +17 -0
  155. package/dist/node_modules/axios/lib/helpers/callbackify.js.map +1 -0
  156. package/dist/node_modules/axios/lib/helpers/combineURLs.js +17 -0
  157. package/dist/node_modules/axios/lib/helpers/combineURLs.js.map +1 -0
  158. package/dist/node_modules/axios/lib/helpers/composeSignals.js +49 -0
  159. package/dist/node_modules/axios/lib/helpers/composeSignals.js.map +1 -0
  160. package/dist/node_modules/axios/lib/helpers/cookies.js +55 -0
  161. package/dist/node_modules/axios/lib/helpers/cookies.js.map +1 -0
  162. package/dist/node_modules/axios/lib/helpers/estimateDataURLDecodedBytes.js +76 -0
  163. package/dist/node_modules/axios/lib/helpers/estimateDataURLDecodedBytes.js.map +1 -0
  164. package/dist/node_modules/axios/lib/helpers/formDataToJSON.js +95 -0
  165. package/dist/node_modules/axios/lib/helpers/formDataToJSON.js.map +1 -0
  166. package/dist/node_modules/axios/lib/helpers/formDataToStream.js +113 -0
  167. package/dist/node_modules/axios/lib/helpers/formDataToStream.js.map +1 -0
  168. package/dist/node_modules/axios/lib/helpers/fromDataURI.js +55 -0
  169. package/dist/node_modules/axios/lib/helpers/fromDataURI.js.map +1 -0
  170. package/dist/node_modules/axios/lib/helpers/isAbsoluteURL.js +17 -0
  171. package/dist/node_modules/axios/lib/helpers/isAbsoluteURL.js.map +1 -0
  172. package/dist/node_modules/axios/lib/helpers/isAxiosError.js +16 -0
  173. package/dist/node_modules/axios/lib/helpers/isAxiosError.js.map +1 -0
  174. package/dist/node_modules/axios/lib/helpers/isURLSameOrigin.js +17 -0
  175. package/dist/node_modules/axios/lib/helpers/isURLSameOrigin.js.map +1 -0
  176. package/dist/node_modules/axios/lib/helpers/parseHeaders.js +57 -0
  177. package/dist/node_modules/axios/lib/helpers/parseHeaders.js.map +1 -0
  178. package/dist/node_modules/axios/lib/helpers/parseProtocol.js +8 -0
  179. package/dist/node_modules/axios/lib/helpers/parseProtocol.js.map +1 -0
  180. package/dist/node_modules/axios/lib/helpers/progressEventReducer.js +47 -0
  181. package/dist/node_modules/axios/lib/helpers/progressEventReducer.js.map +1 -0
  182. package/dist/node_modules/axios/lib/helpers/readBlob.js +16 -0
  183. package/dist/node_modules/axios/lib/helpers/readBlob.js.map +1 -0
  184. package/dist/node_modules/axios/lib/helpers/resolveConfig.js +63 -0
  185. package/dist/node_modules/axios/lib/helpers/resolveConfig.js.map +1 -0
  186. package/dist/node_modules/axios/lib/helpers/speedometer.js +55 -0
  187. package/dist/node_modules/axios/lib/helpers/speedometer.js.map +1 -0
  188. package/dist/node_modules/axios/lib/helpers/spread.js +30 -0
  189. package/dist/node_modules/axios/lib/helpers/spread.js.map +1 -0
  190. package/dist/node_modules/axios/lib/helpers/throttle.js +45 -0
  191. package/dist/node_modules/axios/lib/helpers/throttle.js.map +1 -0
  192. package/dist/node_modules/axios/lib/helpers/toFormData.js +222 -0
  193. package/dist/node_modules/axios/lib/helpers/toFormData.js.map +1 -0
  194. package/dist/node_modules/axios/lib/helpers/toURLEncodedForm.js +21 -0
  195. package/dist/node_modules/axios/lib/helpers/toURLEncodedForm.js.map +1 -0
  196. package/dist/node_modules/axios/lib/helpers/trackStream.js +89 -0
  197. package/dist/node_modules/axios/lib/helpers/trackStream.js.map +1 -0
  198. package/dist/node_modules/axios/lib/helpers/validator.js +101 -0
  199. package/dist/node_modules/axios/lib/helpers/validator.js.map +1 -0
  200. package/dist/node_modules/axios/lib/platform/common/utils.js +46 -0
  201. package/dist/node_modules/axios/lib/platform/common/utils.js.map +1 -0
  202. package/dist/node_modules/axios/lib/platform/index.js +10 -0
  203. package/dist/node_modules/axios/lib/platform/index.js.map +1 -0
  204. package/dist/node_modules/axios/lib/platform/node/classes/FormData.js +3 -0
  205. package/dist/node_modules/axios/lib/platform/node/classes/FormData.js.map +1 -0
  206. package/dist/node_modules/axios/lib/platform/node/classes/URLSearchParams.js +7 -0
  207. package/dist/node_modules/axios/lib/platform/node/classes/URLSearchParams.js.map +1 -0
  208. package/dist/node_modules/axios/lib/platform/node/index.js +41 -0
  209. package/dist/node_modules/axios/lib/platform/node/index.js.map +1 -0
  210. package/dist/node_modules/axios/lib/utils.js +784 -0
  211. package/dist/node_modules/axios/lib/utils.js.map +1 -0
  212. package/dist/node_modules/debug/src/browser.js +287 -0
  213. package/dist/node_modules/debug/src/browser.js.map +1 -0
  214. package/dist/node_modules/debug/src/common.js +304 -0
  215. package/dist/node_modules/debug/src/common.js.map +1 -0
  216. package/dist/node_modules/debug/src/index.js +24 -0
  217. package/dist/node_modules/debug/src/index.js.map +1 -0
  218. package/dist/node_modules/debug/src/node.js +280 -0
  219. package/dist/node_modules/debug/src/node.js.map +1 -0
  220. package/dist/node_modules/follow-redirects/debug.js +20 -0
  221. package/dist/node_modules/follow-redirects/debug.js.map +1 -0
  222. package/dist/node_modules/follow-redirects/index.js +701 -0
  223. package/dist/node_modules/follow-redirects/index.js.map +1 -0
  224. package/dist/node_modules/immer/dist/immer.js +860 -0
  225. package/dist/node_modules/immer/dist/immer.js.map +1 -0
  226. package/dist/node_modules/proxy-from-env/index.js +112 -0
  227. package/dist/node_modules/proxy-from-env/index.js.map +1 -0
  228. package/dist/node_modules/react-redux/dist/react-redux.js +348 -0
  229. package/dist/node_modules/react-redux/dist/react-redux.js.map +1 -0
  230. package/dist/node_modules/redux/dist/redux.js +362 -0
  231. package/dist/node_modules/redux/dist/redux.js.map +1 -0
  232. package/dist/node_modules/redux-thunk/dist/redux-thunk.js +15 -0
  233. package/dist/node_modules/redux-thunk/dist/redux-thunk.js.map +1 -0
  234. package/dist/node_modules/reselect/dist/reselect.js +322 -0
  235. package/dist/node_modules/reselect/dist/reselect.js.map +1 -0
  236. package/dist/node_modules/server-only/index.js +5 -0
  237. package/dist/node_modules/server-only/index.js.map +1 -0
  238. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.development.js +108 -0
  239. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.development.js.map +1 -0
  240. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.production.js +96 -0
  241. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-with-selector.production.js.map +1 -0
  242. package/dist/node_modules/use-sync-external-store/with-selector.js +14 -0
  243. package/dist/node_modules/use-sync-external-store/with-selector.js.map +1 -0
  244. package/dist/store/StoreProvider.d.ts +7 -0
  245. package/dist/store/StoreProvider.d.ts.map +1 -0
  246. package/dist/store/StoreProvider.js +11 -0
  247. package/dist/store/StoreProvider.js.map +1 -0
  248. package/dist/store/features/drawer/drawer.slice.d.ts +12 -0
  249. package/dist/store/features/drawer/drawer.slice.d.ts.map +1 -0
  250. package/dist/store/features/drawer/drawer.slice.js +26 -0
  251. package/dist/store/features/drawer/drawer.slice.js.map +1 -0
  252. package/dist/store/features/toast/toastSlice.d.ts +16 -0
  253. package/dist/store/features/toast/toastSlice.d.ts.map +1 -0
  254. package/dist/store/features/toast/toastSlice.js +26 -0
  255. package/dist/store/features/toast/toastSlice.js.map +1 -0
  256. package/dist/store/hooks.d.ts +10 -0
  257. package/dist/store/hooks.d.ts.map +1 -0
  258. package/dist/store/hooks.js +8 -0
  259. package/dist/store/hooks.js.map +1 -0
  260. package/dist/store/store.d.ts +16 -0
  261. package/dist/store/store.d.ts.map +1 -0
  262. package/dist/store/store.js +13 -0
  263. package/dist/store/store.js.map +1 -0
  264. package/dist/styles.css +2 -0
  265. package/dist/styles.css.map +1 -0
  266. package/package.json +57 -0
@@ -0,0 +1,895 @@
1
+ import utils from '../utils.js';
2
+ import settle from '../core/settle.js';
3
+ import buildFullPath from '../core/buildFullPath.js';
4
+ import buildURL from '../helpers/buildURL.js';
5
+ import '../../../proxy-from-env/index.js';
6
+ import require$$1 from 'http';
7
+ import require$$2 from 'https';
8
+ import http2 from 'http2';
9
+ import util from 'util';
10
+ import followRedirects from '../../../follow-redirects/index.js';
11
+ import zlib from 'zlib';
12
+ import { VERSION } from '../env/data.js';
13
+ import transitionalDefaults from '../defaults/transitional.js';
14
+ import AxiosError from '../core/AxiosError.js';
15
+ import CanceledError from '../cancel/CanceledError.js';
16
+ import platform from '../platform/index.js';
17
+ import fromDataURI from '../helpers/fromDataURI.js';
18
+ import stream from 'stream';
19
+ import AxiosHeaders from '../core/AxiosHeaders.js';
20
+ import AxiosTransformStream from '../helpers/AxiosTransformStream.js';
21
+ import { EventEmitter } from 'events';
22
+ import formDataToStream from '../helpers/formDataToStream.js';
23
+ import readBlob from '../helpers/readBlob.js';
24
+ import ZlibHeaderTransformStream from '../helpers/ZlibHeaderTransformStream.js';
25
+ import callbackify from '../helpers/callbackify.js';
26
+ import { progressEventDecorator, progressEventReducer, asyncDecorator } from '../helpers/progressEventReducer.js';
27
+ import estimateDataURLDecodedBytes from '../helpers/estimateDataURLDecodedBytes.js';
28
+ import { __exports as proxyFromEnv } from '../../../../_virtual/index.js';
29
+
30
+ const zlibOptions = {
31
+ flush: zlib.constants.Z_SYNC_FLUSH,
32
+ finishFlush: zlib.constants.Z_SYNC_FLUSH
33
+ };
34
+
35
+ const brotliOptions = {
36
+ flush: zlib.constants.BROTLI_OPERATION_FLUSH,
37
+ finishFlush: zlib.constants.BROTLI_OPERATION_FLUSH
38
+ };
39
+
40
+ const isBrotliSupported = utils.isFunction(zlib.createBrotliDecompress);
41
+
42
+ const {http: httpFollow, https: httpsFollow} = followRedirects;
43
+
44
+ const isHttps = /https:?/;
45
+
46
+ const supportedProtocols = platform.protocols.map(protocol => {
47
+ return protocol + ':';
48
+ });
49
+
50
+
51
+ const flushOnFinish = (stream, [throttled, flush]) => {
52
+ stream
53
+ .on('end', flush)
54
+ .on('error', flush);
55
+
56
+ return throttled;
57
+ };
58
+
59
+ class Http2Sessions {
60
+ constructor() {
61
+ this.sessions = Object.create(null);
62
+ }
63
+
64
+ getSession(authority, options) {
65
+ options = Object.assign({
66
+ sessionTimeout: 1000
67
+ }, options);
68
+
69
+ let authoritySessions = this.sessions[authority];
70
+
71
+ if (authoritySessions) {
72
+ let len = authoritySessions.length;
73
+
74
+ for (let i = 0; i < len; i++) {
75
+ const [sessionHandle, sessionOptions] = authoritySessions[i];
76
+ if (!sessionHandle.destroyed && !sessionHandle.closed && util.isDeepStrictEqual(sessionOptions, options)) {
77
+ return sessionHandle;
78
+ }
79
+ }
80
+ }
81
+
82
+ const session = http2.connect(authority, options);
83
+
84
+ let removed;
85
+
86
+ const removeSession = () => {
87
+ if (removed) {
88
+ return;
89
+ }
90
+
91
+ removed = true;
92
+
93
+ let entries = authoritySessions, len = entries.length, i = len;
94
+
95
+ while (i--) {
96
+ if (entries[i][0] === session) {
97
+ if (len === 1) {
98
+ delete this.sessions[authority];
99
+ } else {
100
+ entries.splice(i, 1);
101
+ }
102
+ return;
103
+ }
104
+ }
105
+ };
106
+
107
+ const originalRequestFn = session.request;
108
+
109
+ const {sessionTimeout} = options;
110
+
111
+ if(sessionTimeout != null) {
112
+
113
+ let timer;
114
+ let streamsCount = 0;
115
+
116
+ session.request = function () {
117
+ const stream = originalRequestFn.apply(this, arguments);
118
+
119
+ streamsCount++;
120
+
121
+ if (timer) {
122
+ clearTimeout(timer);
123
+ timer = null;
124
+ }
125
+
126
+ stream.once('close', () => {
127
+ if (!--streamsCount) {
128
+ timer = setTimeout(() => {
129
+ timer = null;
130
+ removeSession();
131
+ }, sessionTimeout);
132
+ }
133
+ });
134
+
135
+ return stream;
136
+ };
137
+ }
138
+
139
+ session.once('close', removeSession);
140
+
141
+ let entry = [
142
+ session,
143
+ options
144
+ ];
145
+
146
+ authoritySessions ? authoritySessions.push(entry) : authoritySessions = this.sessions[authority] = [entry];
147
+
148
+ return session;
149
+ }
150
+ }
151
+
152
+ const http2Sessions = new Http2Sessions();
153
+
154
+
155
+ /**
156
+ * If the proxy or config beforeRedirects functions are defined, call them with the options
157
+ * object.
158
+ *
159
+ * @param {Object<string, any>} options - The options object that was passed to the request.
160
+ *
161
+ * @returns {Object<string, any>}
162
+ */
163
+ function dispatchBeforeRedirect(options, responseDetails) {
164
+ if (options.beforeRedirects.proxy) {
165
+ options.beforeRedirects.proxy(options);
166
+ }
167
+ if (options.beforeRedirects.config) {
168
+ options.beforeRedirects.config(options, responseDetails);
169
+ }
170
+ }
171
+
172
+ /**
173
+ * If the proxy or config afterRedirects functions are defined, call them with the options
174
+ *
175
+ * @param {http.ClientRequestArgs} options
176
+ * @param {AxiosProxyConfig} configProxy configuration from Axios options object
177
+ * @param {string} location
178
+ *
179
+ * @returns {http.ClientRequestArgs}
180
+ */
181
+ function setProxy(options, configProxy, location) {
182
+ let proxy = configProxy;
183
+ if (!proxy && proxy !== false) {
184
+ const proxyUrl = proxyFromEnv.getProxyForUrl(location);
185
+ if (proxyUrl) {
186
+ proxy = new URL(proxyUrl);
187
+ }
188
+ }
189
+ if (proxy) {
190
+ // Basic proxy authorization
191
+ if (proxy.username) {
192
+ proxy.auth = (proxy.username || '') + ':' + (proxy.password || '');
193
+ }
194
+
195
+ if (proxy.auth) {
196
+ // Support proxy auth object form
197
+ if (proxy.auth.username || proxy.auth.password) {
198
+ proxy.auth = (proxy.auth.username || '') + ':' + (proxy.auth.password || '');
199
+ }
200
+ const base64 = Buffer
201
+ .from(proxy.auth, 'utf8')
202
+ .toString('base64');
203
+ options.headers['Proxy-Authorization'] = 'Basic ' + base64;
204
+ }
205
+
206
+ options.headers.host = options.hostname + (options.port ? ':' + options.port : '');
207
+ const proxyHost = proxy.hostname || proxy.host;
208
+ options.hostname = proxyHost;
209
+ // Replace 'host' since options is not a URL object
210
+ options.host = proxyHost;
211
+ options.port = proxy.port;
212
+ options.path = location;
213
+ if (proxy.protocol) {
214
+ options.protocol = proxy.protocol.includes(':') ? proxy.protocol : `${proxy.protocol}:`;
215
+ }
216
+ }
217
+
218
+ options.beforeRedirects.proxy = function beforeRedirect(redirectOptions) {
219
+ // Configure proxy for redirected request, passing the original config proxy to apply
220
+ // the exact same logic as if the redirected request was performed by axios directly.
221
+ setProxy(redirectOptions, configProxy, redirectOptions.href);
222
+ };
223
+ }
224
+
225
+ const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(process) === 'process';
226
+
227
+ // temporary hotfix
228
+
229
+ const wrapAsync = (asyncExecutor) => {
230
+ return new Promise((resolve, reject) => {
231
+ let onDone;
232
+ let isDone;
233
+
234
+ const done = (value, isRejected) => {
235
+ if (isDone) return;
236
+ isDone = true;
237
+ onDone && onDone(value, isRejected);
238
+ };
239
+
240
+ const _resolve = (value) => {
241
+ done(value);
242
+ resolve(value);
243
+ };
244
+
245
+ const _reject = (reason) => {
246
+ done(reason, true);
247
+ reject(reason);
248
+ };
249
+
250
+ asyncExecutor(_resolve, _reject, (onDoneHandler) => (onDone = onDoneHandler)).catch(_reject);
251
+ })
252
+ };
253
+
254
+ const resolveFamily = ({address, family}) => {
255
+ if (!utils.isString(address)) {
256
+ throw TypeError('address must be a string');
257
+ }
258
+ return ({
259
+ address,
260
+ family: family || (address.indexOf('.') < 0 ? 6 : 4)
261
+ });
262
+ };
263
+
264
+ const buildAddressEntry = (address, family) => resolveFamily(utils.isObject(address) ? address : {address, family});
265
+
266
+ const http2Transport = {
267
+ request(options, cb) {
268
+ const authority = options.protocol + '//' + options.hostname + ':' + (options.port || 80);
269
+
270
+ const {http2Options, headers} = options;
271
+
272
+ const session = http2Sessions.getSession(authority, http2Options);
273
+
274
+ const {
275
+ HTTP2_HEADER_SCHEME,
276
+ HTTP2_HEADER_METHOD,
277
+ HTTP2_HEADER_PATH,
278
+ HTTP2_HEADER_STATUS
279
+ } = http2.constants;
280
+
281
+ const http2Headers = {
282
+ [HTTP2_HEADER_SCHEME]: options.protocol.replace(':', ''),
283
+ [HTTP2_HEADER_METHOD]: options.method,
284
+ [HTTP2_HEADER_PATH]: options.path,
285
+ };
286
+
287
+ utils.forEach(headers, (header, name) => {
288
+ name.charAt(0) !== ':' && (http2Headers[name] = header);
289
+ });
290
+
291
+ const req = session.request(http2Headers);
292
+
293
+ req.once('response', (responseHeaders) => {
294
+ const response = req; //duplex
295
+
296
+ responseHeaders = Object.assign({}, responseHeaders);
297
+
298
+ const status = responseHeaders[HTTP2_HEADER_STATUS];
299
+
300
+ delete responseHeaders[HTTP2_HEADER_STATUS];
301
+
302
+ response.headers = responseHeaders;
303
+
304
+ response.statusCode = +status;
305
+
306
+ cb(response);
307
+ });
308
+
309
+ return req;
310
+ }
311
+ };
312
+
313
+ /*eslint consistent-return:0*/
314
+ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
315
+ return wrapAsync(async function dispatchHttpRequest(resolve, reject, onDone) {
316
+ let {data, lookup, family, httpVersion = 1, http2Options} = config;
317
+ const {responseType, responseEncoding} = config;
318
+ const method = config.method.toUpperCase();
319
+ let isDone;
320
+ let rejected = false;
321
+ let req;
322
+
323
+ httpVersion = +httpVersion;
324
+
325
+ if (Number.isNaN(httpVersion)) {
326
+ throw TypeError(`Invalid protocol version: '${config.httpVersion}' is not a number`);
327
+ }
328
+
329
+ if (httpVersion !== 1 && httpVersion !== 2) {
330
+ throw TypeError(`Unsupported protocol version '${httpVersion}'`);
331
+ }
332
+
333
+ const isHttp2 = httpVersion === 2;
334
+
335
+ if (lookup) {
336
+ const _lookup = callbackify(lookup, (value) => utils.isArray(value) ? value : [value]);
337
+ // hotfix to support opt.all option which is required for node 20.x
338
+ lookup = (hostname, opt, cb) => {
339
+ _lookup(hostname, opt, (err, arg0, arg1) => {
340
+ if (err) {
341
+ return cb(err);
342
+ }
343
+
344
+ const addresses = utils.isArray(arg0) ? arg0.map(addr => buildAddressEntry(addr)) : [buildAddressEntry(arg0, arg1)];
345
+
346
+ opt.all ? cb(err, addresses) : cb(err, addresses[0].address, addresses[0].family);
347
+ });
348
+ };
349
+ }
350
+
351
+ const abortEmitter = new EventEmitter();
352
+
353
+ function abort(reason) {
354
+ try {
355
+ abortEmitter.emit('abort', !reason || reason.type ? new CanceledError(null, config, req) : reason);
356
+ } catch(err) {
357
+ console.warn('emit error', err);
358
+ }
359
+ }
360
+
361
+ abortEmitter.once('abort', reject);
362
+
363
+ const onFinished = () => {
364
+ if (config.cancelToken) {
365
+ config.cancelToken.unsubscribe(abort);
366
+ }
367
+
368
+ if (config.signal) {
369
+ config.signal.removeEventListener('abort', abort);
370
+ }
371
+
372
+ abortEmitter.removeAllListeners();
373
+ };
374
+
375
+ if (config.cancelToken || config.signal) {
376
+ config.cancelToken && config.cancelToken.subscribe(abort);
377
+ if (config.signal) {
378
+ config.signal.aborted ? abort() : config.signal.addEventListener('abort', abort);
379
+ }
380
+ }
381
+
382
+ onDone((response, isRejected) => {
383
+ isDone = true;
384
+
385
+ if (isRejected) {
386
+ rejected = true;
387
+ onFinished();
388
+ return;
389
+ }
390
+
391
+ const {data} = response;
392
+
393
+ if (data instanceof stream.Readable || data instanceof stream.Duplex) {
394
+ const offListeners = stream.finished(data, () => {
395
+ offListeners();
396
+ onFinished();
397
+ });
398
+ } else {
399
+ onFinished();
400
+ }
401
+ });
402
+
403
+
404
+
405
+
406
+
407
+ // Parse url
408
+ const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
409
+ const parsed = new URL(fullPath, platform.hasBrowserEnv ? platform.origin : undefined);
410
+ const protocol = parsed.protocol || supportedProtocols[0];
411
+
412
+ if (protocol === 'data:') {
413
+ // Apply the same semantics as HTTP: only enforce if a finite, non-negative cap is set.
414
+ if (config.maxContentLength > -1) {
415
+ // Use the exact string passed to fromDataURI (config.url); fall back to fullPath if needed.
416
+ const dataUrl = String(config.url || fullPath || '');
417
+ const estimated = estimateDataURLDecodedBytes(dataUrl);
418
+
419
+ if (estimated > config.maxContentLength) {
420
+ return reject(new AxiosError(
421
+ 'maxContentLength size of ' + config.maxContentLength + ' exceeded',
422
+ AxiosError.ERR_BAD_RESPONSE,
423
+ config
424
+ ));
425
+ }
426
+ }
427
+
428
+ let convertedData;
429
+
430
+ if (method !== 'GET') {
431
+ return settle(resolve, reject, {
432
+ status: 405,
433
+ statusText: 'method not allowed',
434
+ headers: {},
435
+ config
436
+ });
437
+ }
438
+
439
+ try {
440
+ convertedData = fromDataURI(config.url, responseType === 'blob', {
441
+ Blob: config.env && config.env.Blob
442
+ });
443
+ } catch (err) {
444
+ throw AxiosError.from(err, AxiosError.ERR_BAD_REQUEST, config);
445
+ }
446
+
447
+ if (responseType === 'text') {
448
+ convertedData = convertedData.toString(responseEncoding);
449
+
450
+ if (!responseEncoding || responseEncoding === 'utf8') {
451
+ convertedData = utils.stripBOM(convertedData);
452
+ }
453
+ } else if (responseType === 'stream') {
454
+ convertedData = stream.Readable.from(convertedData);
455
+ }
456
+
457
+ return settle(resolve, reject, {
458
+ data: convertedData,
459
+ status: 200,
460
+ statusText: 'OK',
461
+ headers: new AxiosHeaders(),
462
+ config
463
+ });
464
+ }
465
+
466
+ if (supportedProtocols.indexOf(protocol) === -1) {
467
+ return reject(new AxiosError(
468
+ 'Unsupported protocol ' + protocol,
469
+ AxiosError.ERR_BAD_REQUEST,
470
+ config
471
+ ));
472
+ }
473
+
474
+ const headers = AxiosHeaders.from(config.headers).normalize();
475
+
476
+ // Set User-Agent (required by some servers)
477
+ // See https://github.com/axios/axios/issues/69
478
+ // User-Agent is specified; handle case where no UA header is desired
479
+ // Only set header if it hasn't been set in config
480
+ headers.set('User-Agent', 'axios/' + VERSION, false);
481
+
482
+ const {onUploadProgress, onDownloadProgress} = config;
483
+ const maxRate = config.maxRate;
484
+ let maxUploadRate = undefined;
485
+ let maxDownloadRate = undefined;
486
+
487
+ // support for spec compliant FormData objects
488
+ if (utils.isSpecCompliantForm(data)) {
489
+ const userBoundary = headers.getContentType(/boundary=([-_\w\d]{10,70})/i);
490
+
491
+ data = formDataToStream(data, (formHeaders) => {
492
+ headers.set(formHeaders);
493
+ }, {
494
+ tag: `axios-${VERSION}-boundary`,
495
+ boundary: userBoundary && userBoundary[1] || undefined
496
+ });
497
+ // support for https://www.npmjs.com/package/form-data api
498
+ } else if (utils.isFormData(data) && utils.isFunction(data.getHeaders)) {
499
+ headers.set(data.getHeaders());
500
+
501
+ if (!headers.hasContentLength()) {
502
+ try {
503
+ const knownLength = await util.promisify(data.getLength).call(data);
504
+ Number.isFinite(knownLength) && knownLength >= 0 && headers.setContentLength(knownLength);
505
+ /*eslint no-empty:0*/
506
+ } catch (e) {
507
+ }
508
+ }
509
+ } else if (utils.isBlob(data) || utils.isFile(data)) {
510
+ data.size && headers.setContentType(data.type || 'application/octet-stream');
511
+ headers.setContentLength(data.size || 0);
512
+ data = stream.Readable.from(readBlob(data));
513
+ } else if (data && !utils.isStream(data)) {
514
+ if (Buffer.isBuffer(data)) ; else if (utils.isArrayBuffer(data)) {
515
+ data = Buffer.from(new Uint8Array(data));
516
+ } else if (utils.isString(data)) {
517
+ data = Buffer.from(data, 'utf-8');
518
+ } else {
519
+ return reject(new AxiosError(
520
+ 'Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream',
521
+ AxiosError.ERR_BAD_REQUEST,
522
+ config
523
+ ));
524
+ }
525
+
526
+ // Add Content-Length header if data exists
527
+ headers.setContentLength(data.length, false);
528
+
529
+ if (config.maxBodyLength > -1 && data.length > config.maxBodyLength) {
530
+ return reject(new AxiosError(
531
+ 'Request body larger than maxBodyLength limit',
532
+ AxiosError.ERR_BAD_REQUEST,
533
+ config
534
+ ));
535
+ }
536
+ }
537
+
538
+ const contentLength = utils.toFiniteNumber(headers.getContentLength());
539
+
540
+ if (utils.isArray(maxRate)) {
541
+ maxUploadRate = maxRate[0];
542
+ maxDownloadRate = maxRate[1];
543
+ } else {
544
+ maxUploadRate = maxDownloadRate = maxRate;
545
+ }
546
+
547
+ if (data && (onUploadProgress || maxUploadRate)) {
548
+ if (!utils.isStream(data)) {
549
+ data = stream.Readable.from(data, {objectMode: false});
550
+ }
551
+
552
+ data = stream.pipeline([data, new AxiosTransformStream({
553
+ maxRate: utils.toFiniteNumber(maxUploadRate)
554
+ })], utils.noop);
555
+
556
+ onUploadProgress && data.on('progress', flushOnFinish(
557
+ data,
558
+ progressEventDecorator(
559
+ contentLength,
560
+ progressEventReducer(asyncDecorator(onUploadProgress), false, 3)
561
+ )
562
+ ));
563
+ }
564
+
565
+ // HTTP basic authentication
566
+ let auth = undefined;
567
+ if (config.auth) {
568
+ const username = config.auth.username || '';
569
+ const password = config.auth.password || '';
570
+ auth = username + ':' + password;
571
+ }
572
+
573
+ if (!auth && parsed.username) {
574
+ const urlUsername = parsed.username;
575
+ const urlPassword = parsed.password;
576
+ auth = urlUsername + ':' + urlPassword;
577
+ }
578
+
579
+ auth && headers.delete('authorization');
580
+
581
+ let path;
582
+
583
+ try {
584
+ path = buildURL(
585
+ parsed.pathname + parsed.search,
586
+ config.params,
587
+ config.paramsSerializer
588
+ ).replace(/^\?/, '');
589
+ } catch (err) {
590
+ const customErr = new Error(err.message);
591
+ customErr.config = config;
592
+ customErr.url = config.url;
593
+ customErr.exists = true;
594
+ return reject(customErr);
595
+ }
596
+
597
+ headers.set(
598
+ 'Accept-Encoding',
599
+ 'gzip, compress, deflate' + (isBrotliSupported ? ', br' : ''), false
600
+ );
601
+
602
+ const options = {
603
+ path,
604
+ method: method,
605
+ headers: headers.toJSON(),
606
+ agents: { http: config.httpAgent, https: config.httpsAgent },
607
+ auth,
608
+ protocol,
609
+ family,
610
+ beforeRedirect: dispatchBeforeRedirect,
611
+ beforeRedirects: {},
612
+ http2Options
613
+ };
614
+
615
+ // cacheable-lookup integration hotfix
616
+ !utils.isUndefined(lookup) && (options.lookup = lookup);
617
+
618
+ if (config.socketPath) {
619
+ options.socketPath = config.socketPath;
620
+ } else {
621
+ options.hostname = parsed.hostname.startsWith("[") ? parsed.hostname.slice(1, -1) : parsed.hostname;
622
+ options.port = parsed.port;
623
+ setProxy(options, config.proxy, protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path);
624
+ }
625
+
626
+ let transport;
627
+ const isHttpsRequest = isHttps.test(options.protocol);
628
+ options.agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
629
+
630
+ if (isHttp2) {
631
+ transport = http2Transport;
632
+ } else {
633
+ if (config.transport) {
634
+ transport = config.transport;
635
+ } else if (config.maxRedirects === 0) {
636
+ transport = isHttpsRequest ? require$$2 : require$$1;
637
+ } else {
638
+ if (config.maxRedirects) {
639
+ options.maxRedirects = config.maxRedirects;
640
+ }
641
+ if (config.beforeRedirect) {
642
+ options.beforeRedirects.config = config.beforeRedirect;
643
+ }
644
+ transport = isHttpsRequest ? httpsFollow : httpFollow;
645
+ }
646
+ }
647
+
648
+ if (config.maxBodyLength > -1) {
649
+ options.maxBodyLength = config.maxBodyLength;
650
+ } else {
651
+ // follow-redirects does not skip comparison, so it should always succeed for axios -1 unlimited
652
+ options.maxBodyLength = Infinity;
653
+ }
654
+
655
+ if (config.insecureHTTPParser) {
656
+ options.insecureHTTPParser = config.insecureHTTPParser;
657
+ }
658
+
659
+ // Create the request
660
+ req = transport.request(options, function handleResponse(res) {
661
+ if (req.destroyed) return;
662
+
663
+ const streams = [res];
664
+
665
+ const responseLength = utils.toFiniteNumber(res.headers['content-length']);
666
+
667
+ if (onDownloadProgress || maxDownloadRate) {
668
+ const transformStream = new AxiosTransformStream({
669
+ maxRate: utils.toFiniteNumber(maxDownloadRate)
670
+ });
671
+
672
+ onDownloadProgress && transformStream.on('progress', flushOnFinish(
673
+ transformStream,
674
+ progressEventDecorator(
675
+ responseLength,
676
+ progressEventReducer(asyncDecorator(onDownloadProgress), true, 3)
677
+ )
678
+ ));
679
+
680
+ streams.push(transformStream);
681
+ }
682
+
683
+ // decompress the response body transparently if required
684
+ let responseStream = res;
685
+
686
+ // return the last request in case of redirects
687
+ const lastRequest = res.req || req;
688
+
689
+ // if decompress disabled we should not decompress
690
+ if (config.decompress !== false && res.headers['content-encoding']) {
691
+ // if no content, but headers still say that it is encoded,
692
+ // remove the header not confuse downstream operations
693
+ if (method === 'HEAD' || res.statusCode === 204) {
694
+ delete res.headers['content-encoding'];
695
+ }
696
+
697
+ switch ((res.headers['content-encoding'] || '').toLowerCase()) {
698
+ /*eslint default-case:0*/
699
+ case 'gzip':
700
+ case 'x-gzip':
701
+ case 'compress':
702
+ case 'x-compress':
703
+ // add the unzipper to the body stream processing pipeline
704
+ streams.push(zlib.createUnzip(zlibOptions));
705
+
706
+ // remove the content-encoding in order to not confuse downstream operations
707
+ delete res.headers['content-encoding'];
708
+ break;
709
+ case 'deflate':
710
+ streams.push(new ZlibHeaderTransformStream());
711
+
712
+ // add the unzipper to the body stream processing pipeline
713
+ streams.push(zlib.createUnzip(zlibOptions));
714
+
715
+ // remove the content-encoding in order to not confuse downstream operations
716
+ delete res.headers['content-encoding'];
717
+ break;
718
+ case 'br':
719
+ if (isBrotliSupported) {
720
+ streams.push(zlib.createBrotliDecompress(brotliOptions));
721
+ delete res.headers['content-encoding'];
722
+ }
723
+ }
724
+ }
725
+
726
+ responseStream = streams.length > 1 ? stream.pipeline(streams, utils.noop) : streams[0];
727
+
728
+
729
+
730
+ const response = {
731
+ status: res.statusCode,
732
+ statusText: res.statusMessage,
733
+ headers: new AxiosHeaders(res.headers),
734
+ config,
735
+ request: lastRequest
736
+ };
737
+
738
+ if (responseType === 'stream') {
739
+ response.data = responseStream;
740
+ settle(resolve, reject, response);
741
+ } else {
742
+ const responseBuffer = [];
743
+ let totalResponseBytes = 0;
744
+
745
+ responseStream.on('data', function handleStreamData(chunk) {
746
+ responseBuffer.push(chunk);
747
+ totalResponseBytes += chunk.length;
748
+
749
+ // make sure the content length is not over the maxContentLength if specified
750
+ if (config.maxContentLength > -1 && totalResponseBytes > config.maxContentLength) {
751
+ // stream.destroy() emit aborted event before calling reject() on Node.js v16
752
+ rejected = true;
753
+ responseStream.destroy();
754
+ abort(new AxiosError('maxContentLength size of ' + config.maxContentLength + ' exceeded',
755
+ AxiosError.ERR_BAD_RESPONSE, config, lastRequest));
756
+ }
757
+ });
758
+
759
+ responseStream.on('aborted', function handlerStreamAborted() {
760
+ if (rejected) {
761
+ return;
762
+ }
763
+
764
+ const err = new AxiosError(
765
+ 'stream has been aborted',
766
+ AxiosError.ERR_BAD_RESPONSE,
767
+ config,
768
+ lastRequest
769
+ );
770
+ responseStream.destroy(err);
771
+ reject(err);
772
+ });
773
+
774
+ responseStream.on('error', function handleStreamError(err) {
775
+ if (req.destroyed) return;
776
+ reject(AxiosError.from(err, null, config, lastRequest));
777
+ });
778
+
779
+ responseStream.on('end', function handleStreamEnd() {
780
+ try {
781
+ let responseData = responseBuffer.length === 1 ? responseBuffer[0] : Buffer.concat(responseBuffer);
782
+ if (responseType !== 'arraybuffer') {
783
+ responseData = responseData.toString(responseEncoding);
784
+ if (!responseEncoding || responseEncoding === 'utf8') {
785
+ responseData = utils.stripBOM(responseData);
786
+ }
787
+ }
788
+ response.data = responseData;
789
+ } catch (err) {
790
+ return reject(AxiosError.from(err, null, config, response.request, response));
791
+ }
792
+ settle(resolve, reject, response);
793
+ });
794
+ }
795
+
796
+ abortEmitter.once('abort', err => {
797
+ if (!responseStream.destroyed) {
798
+ responseStream.emit('error', err);
799
+ responseStream.destroy();
800
+ }
801
+ });
802
+ });
803
+
804
+ abortEmitter.once('abort', err => {
805
+ if (req.close) {
806
+ req.close();
807
+ } else {
808
+ req.destroy(err);
809
+ }
810
+ });
811
+
812
+ // Handle errors
813
+ req.on('error', function handleRequestError(err) {
814
+ // @todo remove
815
+ // if (req.aborted && err.code !== AxiosError.ERR_FR_TOO_MANY_REDIRECTS) return;
816
+ reject(AxiosError.from(err, null, config, req));
817
+ });
818
+
819
+ // set tcp keep alive to prevent drop connection by peer
820
+ req.on('socket', function handleRequestSocket(socket) {
821
+ // default interval of sending ack packet is 1 minute
822
+ socket.setKeepAlive(true, 1000 * 60);
823
+ });
824
+
825
+ // Handle request timeout
826
+ if (config.timeout) {
827
+ // This is forcing a int timeout to avoid problems if the `req` interface doesn't handle other types.
828
+ const timeout = parseInt(config.timeout, 10);
829
+
830
+ if (Number.isNaN(timeout)) {
831
+ abort(new AxiosError(
832
+ 'error trying to parse `config.timeout` to int',
833
+ AxiosError.ERR_BAD_OPTION_VALUE,
834
+ config,
835
+ req
836
+ ));
837
+
838
+ return;
839
+ }
840
+
841
+ // Sometime, the response will be very slow, and does not respond, the connect event will be block by event loop system.
842
+ // And timer callback will be fired, and abort() will be invoked before connection, then get "socket hang up" and code ECONNRESET.
843
+ // At this time, if we have a large number of request, nodejs will hang up some socket on background. and the number will up and up.
844
+ // And then these socket which be hang up will devouring CPU little by little.
845
+ // ClientRequest.setTimeout will be fired on the specify milliseconds, and can make sure that abort() will be fired after connect.
846
+ req.setTimeout(timeout, function handleRequestTimeout() {
847
+ if (isDone) return;
848
+ let timeoutErrorMessage = config.timeout ? 'timeout of ' + config.timeout + 'ms exceeded' : 'timeout exceeded';
849
+ const transitional = config.transitional || transitionalDefaults;
850
+ if (config.timeoutErrorMessage) {
851
+ timeoutErrorMessage = config.timeoutErrorMessage;
852
+ }
853
+ abort(new AxiosError(
854
+ timeoutErrorMessage,
855
+ transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED,
856
+ config,
857
+ req
858
+ ));
859
+ });
860
+ } else {
861
+ // explicitly reset the socket timeout value for a possible `keep-alive` request
862
+ req.setTimeout(0);
863
+ }
864
+
865
+
866
+ // Send the request
867
+ if (utils.isStream(data)) {
868
+ let ended = false;
869
+ let errored = false;
870
+
871
+ data.on('end', () => {
872
+ ended = true;
873
+ });
874
+
875
+ data.once('error', err => {
876
+ errored = true;
877
+ req.destroy(err);
878
+ });
879
+
880
+ data.on('close', () => {
881
+ if (!ended && !errored) {
882
+ abort(new CanceledError('Request stream has been aborted', config, req));
883
+ }
884
+ });
885
+
886
+ data.pipe(req);
887
+ } else {
888
+ data && req.write(data);
889
+ req.end();
890
+ }
891
+ });
892
+ };
893
+
894
+ export { httpAdapter as default };
895
+ //# sourceMappingURL=http.js.map