@aligent/cdk-prerender-proxy 0.2.5-experimental1 → 0.2.5-experimental2
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.
- package/lib/error-response-construct.d.ts +0 -1
- package/lib/error-response-construct.js +4 -5
- package/lib/handlers/cache-control.ts +21 -0
- package/lib/handlers/error-response.ts +51 -0
- package/lib/handlers/node_modules/.package-lock.json +55 -0
- package/lib/handlers/node_modules/@types/aws-lambda/LICENSE +21 -0
- package/lib/handlers/node_modules/@types/aws-lambda/README.md +16 -0
- package/lib/handlers/node_modules/@types/aws-lambda/common/api-gateway.d.ts +79 -0
- package/lib/handlers/node_modules/@types/aws-lambda/common/cloudfront.d.ts +79 -0
- package/lib/handlers/node_modules/@types/aws-lambda/handler.d.ts +171 -0
- package/lib/handlers/node_modules/@types/aws-lambda/index.d.ts +85 -0
- package/lib/handlers/node_modules/@types/aws-lambda/package.json +210 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/alb.d.ts +48 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/api-gateway-authorizer.d.ts +174 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/api-gateway-proxy.d.ts +187 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/appsync-resolver.d.ts +51 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/cloudformation-custom-resource.d.ts +68 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/cloudfront-request.d.ts +20 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/cloudfront-response.d.ts +21 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/cloudwatch-events.d.ts +8 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/cloudwatch-logs.d.ts +37 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/codebuild-cloudwatch-state.d.ts +104 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/codepipeline-cloudwatch-action.d.ts +31 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/codepipeline-cloudwatch-pipeline.d.ts +32 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/codepipeline-cloudwatch-stage.d.ts +23 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/codepipeline-cloudwatch.d.ts +11 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/codepipeline.d.ts +55 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/_common.d.ts +41 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/create-auth-challenge.d.ts +22 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/custom-email-sender.d.ts +86 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/custom-message.d.ts +44 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/define-auth-challenge.d.ts +21 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/index.d.ts +119 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/post-authentication.d.ts +15 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/post-confirmation.d.ts +22 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/pre-authentication.d.ts +15 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/pre-signup.d.ts +31 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/pre-token-generation.d.ts +45 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/user-migration.d.ts +39 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/cognito-user-pool-trigger/verify-auth-challenge-response.d.ts +20 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/connect-contact-flow.d.ts +65 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/dynamodb-stream.d.ts +45 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/eventbridge.d.ts +18 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/iot.d.ts +28 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/kinesis-firehose-transformation.d.ts +45 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/kinesis-stream.d.ts +28 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/lex.d.ts +116 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/msk.d.ts +21 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/s3-batch.d.ts +41 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/s3.d.ts +60 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/ses.d.ts +103 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/sns.d.ts +38 -0
- package/lib/handlers/node_modules/@types/aws-lambda/trigger/sqs.d.ts +46 -0
- package/lib/handlers/node_modules/@types/node/LICENSE +21 -0
- package/lib/handlers/node_modules/@types/node/README.md +16 -0
- package/lib/handlers/node_modules/@types/node/assert/strict.d.ts +4 -0
- package/lib/handlers/node_modules/@types/node/assert.d.ts +124 -0
- package/lib/handlers/node_modules/@types/node/async_hooks.d.ts +226 -0
- package/lib/handlers/node_modules/@types/node/base.d.ts +19 -0
- package/lib/handlers/node_modules/@types/node/buffer.d.ts +84 -0
- package/lib/handlers/node_modules/@types/node/child_process.d.ts +526 -0
- package/lib/handlers/node_modules/@types/node/cluster.d.ts +262 -0
- package/lib/handlers/node_modules/@types/node/console.d.ts +133 -0
- package/lib/handlers/node_modules/@types/node/constants.d.ts +13 -0
- package/lib/handlers/node_modules/@types/node/crypto.d.ts +1580 -0
- package/lib/handlers/node_modules/@types/node/dgram.d.ts +141 -0
- package/lib/handlers/node_modules/@types/node/diagnostic_channel.d.ts +34 -0
- package/lib/handlers/node_modules/@types/node/dns/promises.d.ts +97 -0
- package/lib/handlers/node_modules/@types/node/dns.d.ts +322 -0
- package/lib/handlers/node_modules/@types/node/domain.d.ts +24 -0
- package/lib/handlers/node_modules/@types/node/events.d.ts +93 -0
- package/lib/handlers/node_modules/@types/node/fs/promises.d.ts +592 -0
- package/lib/handlers/node_modules/@types/node/fs.d.ts +2239 -0
- package/lib/handlers/node_modules/@types/node/globals.d.ts +655 -0
- package/lib/handlers/node_modules/@types/node/globals.global.d.ts +1 -0
- package/lib/handlers/node_modules/@types/node/http.d.ts +434 -0
- package/lib/handlers/node_modules/@types/node/http2.d.ts +976 -0
- package/lib/handlers/node_modules/@types/node/https.d.ts +36 -0
- package/lib/handlers/node_modules/@types/node/index.d.ts +58 -0
- package/lib/handlers/node_modules/@types/node/inspector.d.ts +3041 -0
- package/lib/handlers/node_modules/@types/node/module.d.ts +52 -0
- package/lib/handlers/node_modules/@types/node/net.d.ts +326 -0
- package/lib/handlers/node_modules/@types/node/os.d.ts +239 -0
- package/lib/handlers/node_modules/@types/node/package.json +232 -0
- package/lib/handlers/node_modules/@types/node/path.d.ts +163 -0
- package/lib/handlers/node_modules/@types/node/perf_hooks.d.ts +310 -0
- package/lib/handlers/node_modules/@types/node/process.d.ts +461 -0
- package/lib/handlers/node_modules/@types/node/punycode.d.ts +75 -0
- package/lib/handlers/node_modules/@types/node/querystring.d.ts +28 -0
- package/lib/handlers/node_modules/@types/node/readline.d.ts +192 -0
- package/lib/handlers/node_modules/@types/node/repl.d.ts +395 -0
- package/lib/handlers/node_modules/@types/node/stream/promises.d.ts +67 -0
- package/lib/handlers/node_modules/@types/node/stream.d.ts +471 -0
- package/lib/handlers/node_modules/@types/node/string_decoder.d.ts +7 -0
- package/lib/handlers/node_modules/@types/node/timers/promises.d.ts +21 -0
- package/lib/handlers/node_modules/@types/node/timers.d.ts +27 -0
- package/lib/handlers/node_modules/@types/node/tls.d.ts +793 -0
- package/lib/handlers/node_modules/@types/node/trace_events.d.ts +61 -0
- package/lib/handlers/node_modules/@types/node/ts3.6/assert.d.ts +98 -0
- package/lib/handlers/node_modules/@types/node/ts3.6/base.d.ts +68 -0
- package/lib/handlers/node_modules/@types/node/ts3.6/index.d.ts +7 -0
- package/lib/handlers/node_modules/@types/node/tty.d.ts +66 -0
- package/lib/handlers/node_modules/@types/node/url.d.ts +116 -0
- package/lib/handlers/node_modules/@types/node/util/types.d.ts +53 -0
- package/lib/handlers/node_modules/@types/node/util.d.ts +156 -0
- package/lib/handlers/node_modules/@types/node/v8.d.ts +198 -0
- package/lib/handlers/node_modules/@types/node/vm.d.ts +152 -0
- package/lib/handlers/node_modules/@types/node/wasi.d.ts +86 -0
- package/lib/handlers/node_modules/@types/node/worker_threads.d.ts +282 -0
- package/lib/handlers/node_modules/@types/node/zlib.d.ts +361 -0
- package/lib/handlers/node_modules/axios/CHANGELOG.md +685 -0
- package/lib/handlers/node_modules/axios/LICENSE +19 -0
- package/lib/handlers/node_modules/axios/README.md +800 -0
- package/lib/handlers/node_modules/axios/UPGRADE_GUIDE.md +162 -0
- package/lib/handlers/node_modules/axios/dist/axios.js +1756 -0
- package/lib/handlers/node_modules/axios/dist/axios.map +1 -0
- package/lib/handlers/node_modules/axios/dist/axios.min.js +3 -0
- package/lib/handlers/node_modules/axios/dist/axios.min.map +1 -0
- package/lib/handlers/node_modules/axios/index.d.ts +161 -0
- package/lib/handlers/node_modules/axios/index.js +1 -0
- package/lib/handlers/node_modules/axios/lib/adapters/README.md +37 -0
- package/lib/handlers/node_modules/axios/lib/adapters/http.js +303 -0
- package/lib/handlers/node_modules/axios/lib/adapters/xhr.js +179 -0
- package/lib/handlers/node_modules/axios/lib/axios.js +56 -0
- package/lib/handlers/node_modules/axios/lib/cancel/Cancel.js +19 -0
- package/lib/handlers/node_modules/axios/lib/cancel/CancelToken.js +57 -0
- package/lib/handlers/node_modules/axios/lib/cancel/isCancel.js +5 -0
- package/lib/handlers/node_modules/axios/lib/core/Axios.js +95 -0
- package/lib/handlers/node_modules/axios/lib/core/InterceptorManager.js +52 -0
- package/lib/handlers/node_modules/axios/lib/core/README.md +7 -0
- package/lib/handlers/node_modules/axios/lib/core/buildFullPath.js +20 -0
- package/lib/handlers/node_modules/axios/lib/core/createError.js +18 -0
- package/lib/handlers/node_modules/axios/lib/core/dispatchRequest.js +79 -0
- package/lib/handlers/node_modules/axios/lib/core/enhanceError.js +42 -0
- package/lib/handlers/node_modules/axios/lib/core/mergeConfig.js +87 -0
- package/lib/handlers/node_modules/axios/lib/core/settle.js +25 -0
- package/lib/handlers/node_modules/axios/lib/core/transformData.js +20 -0
- package/lib/handlers/node_modules/axios/lib/defaults.js +98 -0
- package/lib/handlers/node_modules/axios/lib/helpers/README.md +7 -0
- package/lib/handlers/node_modules/axios/lib/helpers/bind.js +11 -0
- package/lib/handlers/node_modules/axios/lib/helpers/buildURL.js +70 -0
- package/lib/handlers/node_modules/axios/lib/helpers/combineURLs.js +14 -0
- package/lib/handlers/node_modules/axios/lib/helpers/cookies.js +53 -0
- package/lib/handlers/node_modules/axios/lib/helpers/deprecatedMethod.js +24 -0
- package/lib/handlers/node_modules/axios/lib/helpers/isAbsoluteURL.js +14 -0
- package/lib/handlers/node_modules/axios/lib/helpers/isAxiosError.js +11 -0
- package/lib/handlers/node_modules/axios/lib/helpers/isURLSameOrigin.js +68 -0
- package/lib/handlers/node_modules/axios/lib/helpers/normalizeHeaderName.js +12 -0
- package/lib/handlers/node_modules/axios/lib/helpers/parseHeaders.js +53 -0
- package/lib/handlers/node_modules/axios/lib/helpers/spread.js +27 -0
- package/lib/handlers/node_modules/axios/lib/utils.js +351 -0
- package/lib/handlers/node_modules/axios/package.json +86 -0
- package/lib/handlers/node_modules/buffer-from/LICENSE +21 -0
- package/lib/handlers/node_modules/buffer-from/index.js +69 -0
- package/lib/handlers/node_modules/buffer-from/package.json +19 -0
- package/lib/handlers/node_modules/buffer-from/readme.md +69 -0
- package/lib/handlers/node_modules/follow-redirects/LICENSE +18 -0
- package/lib/handlers/node_modules/follow-redirects/README.md +148 -0
- package/lib/handlers/node_modules/follow-redirects/debug.js +14 -0
- package/lib/handlers/node_modules/follow-redirects/http.js +1 -0
- package/lib/handlers/node_modules/follow-redirects/https.js +1 -0
- package/lib/handlers/node_modules/follow-redirects/index.js +531 -0
- package/lib/handlers/node_modules/follow-redirects/package.json +59 -0
- package/lib/handlers/node_modules/source-map/CHANGELOG.md +301 -0
- package/lib/handlers/node_modules/source-map/LICENSE +28 -0
- package/lib/handlers/node_modules/source-map/README.md +742 -0
- package/lib/handlers/node_modules/source-map/dist/source-map.debug.js +3234 -0
- package/lib/handlers/node_modules/source-map/dist/source-map.js +3233 -0
- package/lib/handlers/node_modules/source-map/dist/source-map.min.js +2 -0
- package/lib/handlers/node_modules/source-map/dist/source-map.min.js.map +1 -0
- package/lib/handlers/node_modules/source-map/lib/array-set.js +121 -0
- package/lib/handlers/node_modules/source-map/lib/base64-vlq.js +140 -0
- package/lib/handlers/node_modules/source-map/lib/base64.js +67 -0
- package/lib/handlers/node_modules/source-map/lib/binary-search.js +111 -0
- package/lib/handlers/node_modules/source-map/lib/mapping-list.js +79 -0
- package/lib/handlers/node_modules/source-map/lib/quick-sort.js +114 -0
- package/lib/handlers/node_modules/source-map/lib/source-map-consumer.js +1145 -0
- package/lib/handlers/node_modules/source-map/lib/source-map-generator.js +425 -0
- package/lib/handlers/node_modules/source-map/lib/source-node.js +413 -0
- package/lib/handlers/node_modules/source-map/lib/util.js +488 -0
- package/lib/handlers/node_modules/source-map/package.json +73 -0
- package/lib/handlers/node_modules/source-map/source-map.d.ts +98 -0
- package/lib/handlers/node_modules/source-map/source-map.js +8 -0
- package/lib/handlers/node_modules/source-map-support/LICENSE.md +21 -0
- package/lib/handlers/node_modules/source-map-support/README.md +284 -0
- package/lib/handlers/node_modules/source-map-support/browser-source-map-support.js +114 -0
- package/lib/handlers/node_modules/source-map-support/package.json +31 -0
- package/lib/handlers/node_modules/source-map-support/register.js +1 -0
- package/lib/handlers/node_modules/source-map-support/source-map-support.js +604 -0
- package/lib/handlers/package-lock.json +108 -0
- package/lib/handlers/package.json +13 -0
- package/lib/handlers/prerender-check.ts +27 -0
- package/lib/handlers/prerender.ts +43 -0
- package/lib/handlers/tsconfig.json +24 -0
- package/lib/prerender-cf-cache-control-construct.d.ts +0 -1
- package/lib/prerender-cf-cache-control-construct.js +4 -5
- package/lib/prerender-check-construct.d.ts +0 -1
- package/lib/prerender-check-construct.js +4 -5
- package/lib/prerender-construct.d.ts +0 -1
- package/lib/prerender-construct.js +4 -5
- package/package.json +3 -3
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
export interface AxiosTransformer {
|
|
2
|
+
(data: any, headers?: any): any;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export interface AxiosAdapter {
|
|
6
|
+
(config: AxiosRequestConfig): AxiosPromise<any>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface AxiosBasicCredentials {
|
|
10
|
+
username: string;
|
|
11
|
+
password: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface AxiosProxyConfig {
|
|
15
|
+
host: string;
|
|
16
|
+
port: number;
|
|
17
|
+
auth?: {
|
|
18
|
+
username: string;
|
|
19
|
+
password:string;
|
|
20
|
+
};
|
|
21
|
+
protocol?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type Method =
|
|
25
|
+
| 'get' | 'GET'
|
|
26
|
+
| 'delete' | 'DELETE'
|
|
27
|
+
| 'head' | 'HEAD'
|
|
28
|
+
| 'options' | 'OPTIONS'
|
|
29
|
+
| 'post' | 'POST'
|
|
30
|
+
| 'put' | 'PUT'
|
|
31
|
+
| 'patch' | 'PATCH'
|
|
32
|
+
| 'purge' | 'PURGE'
|
|
33
|
+
| 'link' | 'LINK'
|
|
34
|
+
| 'unlink' | 'UNLINK'
|
|
35
|
+
|
|
36
|
+
export type ResponseType =
|
|
37
|
+
| 'arraybuffer'
|
|
38
|
+
| 'blob'
|
|
39
|
+
| 'document'
|
|
40
|
+
| 'json'
|
|
41
|
+
| 'text'
|
|
42
|
+
| 'stream'
|
|
43
|
+
|
|
44
|
+
export interface AxiosRequestConfig {
|
|
45
|
+
url?: string;
|
|
46
|
+
method?: Method;
|
|
47
|
+
baseURL?: string;
|
|
48
|
+
transformRequest?: AxiosTransformer | AxiosTransformer[];
|
|
49
|
+
transformResponse?: AxiosTransformer | AxiosTransformer[];
|
|
50
|
+
headers?: any;
|
|
51
|
+
params?: any;
|
|
52
|
+
paramsSerializer?: (params: any) => string;
|
|
53
|
+
data?: any;
|
|
54
|
+
timeout?: number;
|
|
55
|
+
timeoutErrorMessage?: string;
|
|
56
|
+
withCredentials?: boolean;
|
|
57
|
+
adapter?: AxiosAdapter;
|
|
58
|
+
auth?: AxiosBasicCredentials;
|
|
59
|
+
responseType?: ResponseType;
|
|
60
|
+
xsrfCookieName?: string;
|
|
61
|
+
xsrfHeaderName?: string;
|
|
62
|
+
onUploadProgress?: (progressEvent: any) => void;
|
|
63
|
+
onDownloadProgress?: (progressEvent: any) => void;
|
|
64
|
+
maxContentLength?: number;
|
|
65
|
+
validateStatus?: ((status: number) => boolean) | null;
|
|
66
|
+
maxBodyLength?: number;
|
|
67
|
+
maxRedirects?: number;
|
|
68
|
+
socketPath?: string | null;
|
|
69
|
+
httpAgent?: any;
|
|
70
|
+
httpsAgent?: any;
|
|
71
|
+
proxy?: AxiosProxyConfig | false;
|
|
72
|
+
cancelToken?: CancelToken;
|
|
73
|
+
decompress?: boolean;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface AxiosResponse<T = any> {
|
|
77
|
+
data: T;
|
|
78
|
+
status: number;
|
|
79
|
+
statusText: string;
|
|
80
|
+
headers: any;
|
|
81
|
+
config: AxiosRequestConfig;
|
|
82
|
+
request?: any;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface AxiosError<T = any> extends Error {
|
|
86
|
+
config: AxiosRequestConfig;
|
|
87
|
+
code?: string;
|
|
88
|
+
request?: any;
|
|
89
|
+
response?: AxiosResponse<T>;
|
|
90
|
+
isAxiosError: boolean;
|
|
91
|
+
toJSON: () => object;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface AxiosPromise<T = any> extends Promise<AxiosResponse<T>> {
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface CancelStatic {
|
|
98
|
+
new (message?: string): Cancel;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface Cancel {
|
|
102
|
+
message: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface Canceler {
|
|
106
|
+
(message?: string): void;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface CancelTokenStatic {
|
|
110
|
+
new (executor: (cancel: Canceler) => void): CancelToken;
|
|
111
|
+
source(): CancelTokenSource;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export interface CancelToken {
|
|
115
|
+
promise: Promise<Cancel>;
|
|
116
|
+
reason?: Cancel;
|
|
117
|
+
throwIfRequested(): void;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface CancelTokenSource {
|
|
121
|
+
token: CancelToken;
|
|
122
|
+
cancel: Canceler;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface AxiosInterceptorManager<V> {
|
|
126
|
+
use(onFulfilled?: (value: V) => V | Promise<V>, onRejected?: (error: any) => any): number;
|
|
127
|
+
eject(id: number): void;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface AxiosInstance {
|
|
131
|
+
(config: AxiosRequestConfig): AxiosPromise;
|
|
132
|
+
(url: string, config?: AxiosRequestConfig): AxiosPromise;
|
|
133
|
+
defaults: AxiosRequestConfig;
|
|
134
|
+
interceptors: {
|
|
135
|
+
request: AxiosInterceptorManager<AxiosRequestConfig>;
|
|
136
|
+
response: AxiosInterceptorManager<AxiosResponse>;
|
|
137
|
+
};
|
|
138
|
+
getUri(config?: AxiosRequestConfig): string;
|
|
139
|
+
request<T = any, R = AxiosResponse<T>> (config: AxiosRequestConfig): Promise<R>;
|
|
140
|
+
get<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
|
|
141
|
+
delete<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
|
|
142
|
+
head<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
|
|
143
|
+
options<T = any, R = AxiosResponse<T>>(url: string, config?: AxiosRequestConfig): Promise<R>;
|
|
144
|
+
post<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
|
|
145
|
+
put<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
|
|
146
|
+
patch<T = any, R = AxiosResponse<T>>(url: string, data?: any, config?: AxiosRequestConfig): Promise<R>;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface AxiosStatic extends AxiosInstance {
|
|
150
|
+
create(config?: AxiosRequestConfig): AxiosInstance;
|
|
151
|
+
Cancel: CancelStatic;
|
|
152
|
+
CancelToken: CancelTokenStatic;
|
|
153
|
+
isCancel(value: any): boolean;
|
|
154
|
+
all<T>(values: (T | Promise<T>)[]): Promise<T[]>;
|
|
155
|
+
spread<T, R>(callback: (...args: T[]) => R): (array: T[]) => R;
|
|
156
|
+
isAxiosError(payload: any): payload is AxiosError;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
declare const axios: AxiosStatic;
|
|
160
|
+
|
|
161
|
+
export default axios;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./lib/axios');
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# axios // adapters
|
|
2
|
+
|
|
3
|
+
The modules under `adapters/` are modules that handle dispatching a request and settling a returned `Promise` once a response is received.
|
|
4
|
+
|
|
5
|
+
## Example
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
var settle = require('./../core/settle');
|
|
9
|
+
|
|
10
|
+
module.exports = function myAdapter(config) {
|
|
11
|
+
// At this point:
|
|
12
|
+
// - config has been merged with defaults
|
|
13
|
+
// - request transformers have already run
|
|
14
|
+
// - request interceptors have already run
|
|
15
|
+
|
|
16
|
+
// Make the request using config provided
|
|
17
|
+
// Upon response settle the Promise
|
|
18
|
+
|
|
19
|
+
return new Promise(function(resolve, reject) {
|
|
20
|
+
|
|
21
|
+
var response = {
|
|
22
|
+
data: responseData,
|
|
23
|
+
status: request.status,
|
|
24
|
+
statusText: request.statusText,
|
|
25
|
+
headers: responseHeaders,
|
|
26
|
+
config: config,
|
|
27
|
+
request: request
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
settle(resolve, reject, response);
|
|
31
|
+
|
|
32
|
+
// From here:
|
|
33
|
+
// - response transformers will run
|
|
34
|
+
// - response interceptors will run
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
```
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('./../utils');
|
|
4
|
+
var settle = require('./../core/settle');
|
|
5
|
+
var buildFullPath = require('../core/buildFullPath');
|
|
6
|
+
var buildURL = require('./../helpers/buildURL');
|
|
7
|
+
var http = require('http');
|
|
8
|
+
var https = require('https');
|
|
9
|
+
var httpFollow = require('follow-redirects').http;
|
|
10
|
+
var httpsFollow = require('follow-redirects').https;
|
|
11
|
+
var url = require('url');
|
|
12
|
+
var zlib = require('zlib');
|
|
13
|
+
var pkg = require('./../../package.json');
|
|
14
|
+
var createError = require('../core/createError');
|
|
15
|
+
var enhanceError = require('../core/enhanceError');
|
|
16
|
+
|
|
17
|
+
var isHttps = /https:?/;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param {http.ClientRequestArgs} options
|
|
22
|
+
* @param {AxiosProxyConfig} proxy
|
|
23
|
+
* @param {string} location
|
|
24
|
+
*/
|
|
25
|
+
function setProxy(options, proxy, location) {
|
|
26
|
+
options.hostname = proxy.host;
|
|
27
|
+
options.host = proxy.host;
|
|
28
|
+
options.port = proxy.port;
|
|
29
|
+
options.path = location;
|
|
30
|
+
|
|
31
|
+
// Basic proxy authorization
|
|
32
|
+
if (proxy.auth) {
|
|
33
|
+
var base64 = Buffer.from(proxy.auth.username + ':' + proxy.auth.password, 'utf8').toString('base64');
|
|
34
|
+
options.headers['Proxy-Authorization'] = 'Basic ' + base64;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// If a proxy is used, any redirects must also pass through the proxy
|
|
38
|
+
options.beforeRedirect = function beforeRedirect(redirection) {
|
|
39
|
+
redirection.headers.host = redirection.host;
|
|
40
|
+
setProxy(redirection, proxy, redirection.href);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/*eslint consistent-return:0*/
|
|
45
|
+
module.exports = function httpAdapter(config) {
|
|
46
|
+
return new Promise(function dispatchHttpRequest(resolvePromise, rejectPromise) {
|
|
47
|
+
var resolve = function resolve(value) {
|
|
48
|
+
resolvePromise(value);
|
|
49
|
+
};
|
|
50
|
+
var reject = function reject(value) {
|
|
51
|
+
rejectPromise(value);
|
|
52
|
+
};
|
|
53
|
+
var data = config.data;
|
|
54
|
+
var headers = config.headers;
|
|
55
|
+
|
|
56
|
+
// Set User-Agent (required by some servers)
|
|
57
|
+
// Only set header if it hasn't been set in config
|
|
58
|
+
// See https://github.com/axios/axios/issues/69
|
|
59
|
+
if (!headers['User-Agent'] && !headers['user-agent']) {
|
|
60
|
+
headers['User-Agent'] = 'axios/' + pkg.version;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (data && !utils.isStream(data)) {
|
|
64
|
+
if (Buffer.isBuffer(data)) {
|
|
65
|
+
// Nothing to do...
|
|
66
|
+
} else if (utils.isArrayBuffer(data)) {
|
|
67
|
+
data = Buffer.from(new Uint8Array(data));
|
|
68
|
+
} else if (utils.isString(data)) {
|
|
69
|
+
data = Buffer.from(data, 'utf-8');
|
|
70
|
+
} else {
|
|
71
|
+
return reject(createError(
|
|
72
|
+
'Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream',
|
|
73
|
+
config
|
|
74
|
+
));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Add Content-Length header if data exists
|
|
78
|
+
headers['Content-Length'] = data.length;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// HTTP basic authentication
|
|
82
|
+
var auth = undefined;
|
|
83
|
+
if (config.auth) {
|
|
84
|
+
var username = config.auth.username || '';
|
|
85
|
+
var password = config.auth.password || '';
|
|
86
|
+
auth = username + ':' + password;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Parse url
|
|
90
|
+
var fullPath = buildFullPath(config.baseURL, config.url);
|
|
91
|
+
var parsed = url.parse(fullPath);
|
|
92
|
+
var protocol = parsed.protocol || 'http:';
|
|
93
|
+
|
|
94
|
+
if (!auth && parsed.auth) {
|
|
95
|
+
var urlAuth = parsed.auth.split(':');
|
|
96
|
+
var urlUsername = urlAuth[0] || '';
|
|
97
|
+
var urlPassword = urlAuth[1] || '';
|
|
98
|
+
auth = urlUsername + ':' + urlPassword;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (auth) {
|
|
102
|
+
delete headers.Authorization;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
var isHttpsRequest = isHttps.test(protocol);
|
|
106
|
+
var agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
|
|
107
|
+
|
|
108
|
+
var options = {
|
|
109
|
+
path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
|
|
110
|
+
method: config.method.toUpperCase(),
|
|
111
|
+
headers: headers,
|
|
112
|
+
agent: agent,
|
|
113
|
+
agents: { http: config.httpAgent, https: config.httpsAgent },
|
|
114
|
+
auth: auth
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
if (config.socketPath) {
|
|
118
|
+
options.socketPath = config.socketPath;
|
|
119
|
+
} else {
|
|
120
|
+
options.hostname = parsed.hostname;
|
|
121
|
+
options.port = parsed.port;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
var proxy = config.proxy;
|
|
125
|
+
if (!proxy && proxy !== false) {
|
|
126
|
+
var proxyEnv = protocol.slice(0, -1) + '_proxy';
|
|
127
|
+
var proxyUrl = process.env[proxyEnv] || process.env[proxyEnv.toUpperCase()];
|
|
128
|
+
if (proxyUrl) {
|
|
129
|
+
var parsedProxyUrl = url.parse(proxyUrl);
|
|
130
|
+
var noProxyEnv = process.env.no_proxy || process.env.NO_PROXY;
|
|
131
|
+
var shouldProxy = true;
|
|
132
|
+
|
|
133
|
+
if (noProxyEnv) {
|
|
134
|
+
var noProxy = noProxyEnv.split(',').map(function trim(s) {
|
|
135
|
+
return s.trim();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
shouldProxy = !noProxy.some(function proxyMatch(proxyElement) {
|
|
139
|
+
if (!proxyElement) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
if (proxyElement === '*') {
|
|
143
|
+
return true;
|
|
144
|
+
}
|
|
145
|
+
if (proxyElement[0] === '.' &&
|
|
146
|
+
parsed.hostname.substr(parsed.hostname.length - proxyElement.length) === proxyElement) {
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return parsed.hostname === proxyElement;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (shouldProxy) {
|
|
155
|
+
proxy = {
|
|
156
|
+
host: parsedProxyUrl.hostname,
|
|
157
|
+
port: parsedProxyUrl.port,
|
|
158
|
+
protocol: parsedProxyUrl.protocol
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
if (parsedProxyUrl.auth) {
|
|
162
|
+
var proxyUrlAuth = parsedProxyUrl.auth.split(':');
|
|
163
|
+
proxy.auth = {
|
|
164
|
+
username: proxyUrlAuth[0],
|
|
165
|
+
password: proxyUrlAuth[1]
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (proxy) {
|
|
173
|
+
options.headers.host = parsed.hostname + (parsed.port ? ':' + parsed.port : '');
|
|
174
|
+
setProxy(options, proxy, protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
var transport;
|
|
178
|
+
var isHttpsProxy = isHttpsRequest && (proxy ? isHttps.test(proxy.protocol) : true);
|
|
179
|
+
if (config.transport) {
|
|
180
|
+
transport = config.transport;
|
|
181
|
+
} else if (config.maxRedirects === 0) {
|
|
182
|
+
transport = isHttpsProxy ? https : http;
|
|
183
|
+
} else {
|
|
184
|
+
if (config.maxRedirects) {
|
|
185
|
+
options.maxRedirects = config.maxRedirects;
|
|
186
|
+
}
|
|
187
|
+
transport = isHttpsProxy ? httpsFollow : httpFollow;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (config.maxBodyLength > -1) {
|
|
191
|
+
options.maxBodyLength = config.maxBodyLength;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Create the request
|
|
195
|
+
var req = transport.request(options, function handleResponse(res) {
|
|
196
|
+
if (req.aborted) return;
|
|
197
|
+
|
|
198
|
+
// uncompress the response body transparently if required
|
|
199
|
+
var stream = res;
|
|
200
|
+
|
|
201
|
+
// return the last request in case of redirects
|
|
202
|
+
var lastRequest = res.req || req;
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
// if no content, is HEAD request or decompress disabled we should not decompress
|
|
206
|
+
if (res.statusCode !== 204 && lastRequest.method !== 'HEAD' && config.decompress !== false) {
|
|
207
|
+
switch (res.headers['content-encoding']) {
|
|
208
|
+
/*eslint default-case:0*/
|
|
209
|
+
case 'gzip':
|
|
210
|
+
case 'compress':
|
|
211
|
+
case 'deflate':
|
|
212
|
+
// add the unzipper to the body stream processing pipeline
|
|
213
|
+
stream = stream.pipe(zlib.createUnzip());
|
|
214
|
+
|
|
215
|
+
// remove the content-encoding in order to not confuse downstream operations
|
|
216
|
+
delete res.headers['content-encoding'];
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
var response = {
|
|
222
|
+
status: res.statusCode,
|
|
223
|
+
statusText: res.statusMessage,
|
|
224
|
+
headers: res.headers,
|
|
225
|
+
config: config,
|
|
226
|
+
request: lastRequest
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
if (config.responseType === 'stream') {
|
|
230
|
+
response.data = stream;
|
|
231
|
+
settle(resolve, reject, response);
|
|
232
|
+
} else {
|
|
233
|
+
var responseBuffer = [];
|
|
234
|
+
stream.on('data', function handleStreamData(chunk) {
|
|
235
|
+
responseBuffer.push(chunk);
|
|
236
|
+
|
|
237
|
+
// make sure the content length is not over the maxContentLength if specified
|
|
238
|
+
if (config.maxContentLength > -1 && Buffer.concat(responseBuffer).length > config.maxContentLength) {
|
|
239
|
+
stream.destroy();
|
|
240
|
+
reject(createError('maxContentLength size of ' + config.maxContentLength + ' exceeded',
|
|
241
|
+
config, null, lastRequest));
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
stream.on('error', function handleStreamError(err) {
|
|
246
|
+
if (req.aborted) return;
|
|
247
|
+
reject(enhanceError(err, config, null, lastRequest));
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
stream.on('end', function handleStreamEnd() {
|
|
251
|
+
var responseData = Buffer.concat(responseBuffer);
|
|
252
|
+
if (config.responseType !== 'arraybuffer') {
|
|
253
|
+
responseData = responseData.toString(config.responseEncoding);
|
|
254
|
+
if (!config.responseEncoding || config.responseEncoding === 'utf8') {
|
|
255
|
+
responseData = utils.stripBOM(responseData);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
response.data = responseData;
|
|
260
|
+
settle(resolve, reject, response);
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
// Handle errors
|
|
266
|
+
req.on('error', function handleRequestError(err) {
|
|
267
|
+
if (req.aborted && err.code !== 'ERR_FR_TOO_MANY_REDIRECTS') return;
|
|
268
|
+
reject(enhanceError(err, config, null, req));
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
// Handle request timeout
|
|
272
|
+
if (config.timeout) {
|
|
273
|
+
// Sometime, the response will be very slow, and does not respond, the connect event will be block by event loop system.
|
|
274
|
+
// And timer callback will be fired, and abort() will be invoked before connection, then get "socket hang up" and code ECONNRESET.
|
|
275
|
+
// 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.
|
|
276
|
+
// And then these socket which be hang up will devoring CPU little by little.
|
|
277
|
+
// ClientRequest.setTimeout will be fired on the specify milliseconds, and can make sure that abort() will be fired after connect.
|
|
278
|
+
req.setTimeout(config.timeout, function handleRequestTimeout() {
|
|
279
|
+
req.abort();
|
|
280
|
+
reject(createError('timeout of ' + config.timeout + 'ms exceeded', config, 'ECONNABORTED', req));
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (config.cancelToken) {
|
|
285
|
+
// Handle cancellation
|
|
286
|
+
config.cancelToken.promise.then(function onCanceled(cancel) {
|
|
287
|
+
if (req.aborted) return;
|
|
288
|
+
|
|
289
|
+
req.abort();
|
|
290
|
+
reject(cancel);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Send the request
|
|
295
|
+
if (utils.isStream(data)) {
|
|
296
|
+
data.on('error', function handleStreamError(err) {
|
|
297
|
+
reject(enhanceError(err, config, null, req));
|
|
298
|
+
}).pipe(req);
|
|
299
|
+
} else {
|
|
300
|
+
req.end(data);
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var utils = require('./../utils');
|
|
4
|
+
var settle = require('./../core/settle');
|
|
5
|
+
var cookies = require('./../helpers/cookies');
|
|
6
|
+
var buildURL = require('./../helpers/buildURL');
|
|
7
|
+
var buildFullPath = require('../core/buildFullPath');
|
|
8
|
+
var parseHeaders = require('./../helpers/parseHeaders');
|
|
9
|
+
var isURLSameOrigin = require('./../helpers/isURLSameOrigin');
|
|
10
|
+
var createError = require('../core/createError');
|
|
11
|
+
|
|
12
|
+
module.exports = function xhrAdapter(config) {
|
|
13
|
+
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
|
14
|
+
var requestData = config.data;
|
|
15
|
+
var requestHeaders = config.headers;
|
|
16
|
+
|
|
17
|
+
if (utils.isFormData(requestData)) {
|
|
18
|
+
delete requestHeaders['Content-Type']; // Let the browser set it
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
var request = new XMLHttpRequest();
|
|
22
|
+
|
|
23
|
+
// HTTP basic authentication
|
|
24
|
+
if (config.auth) {
|
|
25
|
+
var username = config.auth.username || '';
|
|
26
|
+
var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
|
|
27
|
+
requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var fullPath = buildFullPath(config.baseURL, config.url);
|
|
31
|
+
request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
|
|
32
|
+
|
|
33
|
+
// Set the request timeout in MS
|
|
34
|
+
request.timeout = config.timeout;
|
|
35
|
+
|
|
36
|
+
// Listen for ready state
|
|
37
|
+
request.onreadystatechange = function handleLoad() {
|
|
38
|
+
if (!request || request.readyState !== 4) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// The request errored out and we didn't get a response, this will be
|
|
43
|
+
// handled by onerror instead
|
|
44
|
+
// With one exception: request that using file: protocol, most browsers
|
|
45
|
+
// will return status as 0 even though it's a successful request
|
|
46
|
+
if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Prepare the response
|
|
51
|
+
var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null;
|
|
52
|
+
var responseData = !config.responseType || config.responseType === 'text' ? request.responseText : request.response;
|
|
53
|
+
var response = {
|
|
54
|
+
data: responseData,
|
|
55
|
+
status: request.status,
|
|
56
|
+
statusText: request.statusText,
|
|
57
|
+
headers: responseHeaders,
|
|
58
|
+
config: config,
|
|
59
|
+
request: request
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
settle(resolve, reject, response);
|
|
63
|
+
|
|
64
|
+
// Clean up request
|
|
65
|
+
request = null;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// Handle browser request cancellation (as opposed to a manual cancellation)
|
|
69
|
+
request.onabort = function handleAbort() {
|
|
70
|
+
if (!request) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
reject(createError('Request aborted', config, 'ECONNABORTED', request));
|
|
75
|
+
|
|
76
|
+
// Clean up request
|
|
77
|
+
request = null;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// Handle low level network errors
|
|
81
|
+
request.onerror = function handleError() {
|
|
82
|
+
// Real errors are hidden from us by the browser
|
|
83
|
+
// onerror should only fire if it's a network error
|
|
84
|
+
reject(createError('Network Error', config, null, request));
|
|
85
|
+
|
|
86
|
+
// Clean up request
|
|
87
|
+
request = null;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// Handle timeout
|
|
91
|
+
request.ontimeout = function handleTimeout() {
|
|
92
|
+
var timeoutErrorMessage = 'timeout of ' + config.timeout + 'ms exceeded';
|
|
93
|
+
if (config.timeoutErrorMessage) {
|
|
94
|
+
timeoutErrorMessage = config.timeoutErrorMessage;
|
|
95
|
+
}
|
|
96
|
+
reject(createError(timeoutErrorMessage, config, 'ECONNABORTED',
|
|
97
|
+
request));
|
|
98
|
+
|
|
99
|
+
// Clean up request
|
|
100
|
+
request = null;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// Add xsrf header
|
|
104
|
+
// This is only done if running in a standard browser environment.
|
|
105
|
+
// Specifically not if we're in a web worker, or react-native.
|
|
106
|
+
if (utils.isStandardBrowserEnv()) {
|
|
107
|
+
// Add xsrf header
|
|
108
|
+
var xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath)) && config.xsrfCookieName ?
|
|
109
|
+
cookies.read(config.xsrfCookieName) :
|
|
110
|
+
undefined;
|
|
111
|
+
|
|
112
|
+
if (xsrfValue) {
|
|
113
|
+
requestHeaders[config.xsrfHeaderName] = xsrfValue;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Add headers to the request
|
|
118
|
+
if ('setRequestHeader' in request) {
|
|
119
|
+
utils.forEach(requestHeaders, function setRequestHeader(val, key) {
|
|
120
|
+
if (typeof requestData === 'undefined' && key.toLowerCase() === 'content-type') {
|
|
121
|
+
// Remove Content-Type if data is undefined
|
|
122
|
+
delete requestHeaders[key];
|
|
123
|
+
} else {
|
|
124
|
+
// Otherwise add header to the request
|
|
125
|
+
request.setRequestHeader(key, val);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Add withCredentials to request if needed
|
|
131
|
+
if (!utils.isUndefined(config.withCredentials)) {
|
|
132
|
+
request.withCredentials = !!config.withCredentials;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Add responseType to request if needed
|
|
136
|
+
if (config.responseType) {
|
|
137
|
+
try {
|
|
138
|
+
request.responseType = config.responseType;
|
|
139
|
+
} catch (e) {
|
|
140
|
+
// Expected DOMException thrown by browsers not compatible XMLHttpRequest Level 2.
|
|
141
|
+
// But, this can be suppressed for 'json' type as it can be parsed by default 'transformResponse' function.
|
|
142
|
+
if (config.responseType !== 'json') {
|
|
143
|
+
throw e;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Handle progress if needed
|
|
149
|
+
if (typeof config.onDownloadProgress === 'function') {
|
|
150
|
+
request.addEventListener('progress', config.onDownloadProgress);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Not all browsers support upload events
|
|
154
|
+
if (typeof config.onUploadProgress === 'function' && request.upload) {
|
|
155
|
+
request.upload.addEventListener('progress', config.onUploadProgress);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (config.cancelToken) {
|
|
159
|
+
// Handle cancellation
|
|
160
|
+
config.cancelToken.promise.then(function onCanceled(cancel) {
|
|
161
|
+
if (!request) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
request.abort();
|
|
166
|
+
reject(cancel);
|
|
167
|
+
// Clean up request
|
|
168
|
+
request = null;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (!requestData) {
|
|
173
|
+
requestData = null;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Send the request
|
|
177
|
+
request.send(requestData);
|
|
178
|
+
});
|
|
179
|
+
};
|