@aws-sdk/xhr-http-handler 3.131.0
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/CHANGELOG.md +11 -0
- package/LICENSE +201 -0
- package/README.md +131 -0
- package/dist-cjs/index.js +4 -0
- package/dist-cjs/request-timeout.js +13 -0
- package/dist-cjs/xhr-http-handler.js +191 -0
- package/dist-es/index.js +1 -0
- package/dist-es/request-timeout.js +12 -0
- package/dist-es/xhr-http-handler.js +223 -0
- package/dist-types/index.d.ts +1 -0
- package/dist-types/request-timeout.d.ts +1 -0
- package/dist-types/ts3.4/index.d.ts +1 -0
- package/dist-types/ts3.4/request-timeout.d.ts +1 -0
- package/dist-types/ts3.4/xhr-http-handler.d.ts +35 -0
- package/dist-types/xhr-http-handler.d.ts +64 -0
- package/package.json +55 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# [3.131.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.130.0...v3.131.0) (2022-07-15)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **xhr-http-handler:** add XMLHttpRequest http handler to use with lib-storage Upload ([#3798](https://github.com/aws/aws-sdk-js-v3/issues/3798)) ([7462b07](https://github.com/aws/aws-sdk-js-v3/commit/7462b0731e54a29290b9b4c359a7f5581a3c78f9))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2018-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# @aws-sdk/xhr-http-handler
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@aws-sdk/xhr-http-handler)
|
|
4
|
+
[](https://www.npmjs.com/package/@aws-sdk/xhr-http-handler)
|
|
5
|
+
|
|
6
|
+
This `HttpHandler` is based on `XMLHttpRequest` and can be substituted if
|
|
7
|
+
requiring a specific use case not covered by `fetch`.
|
|
8
|
+
|
|
9
|
+
## Warning :warning:
|
|
10
|
+
|
|
11
|
+
The recommended `HttpHandler` for browser-like environments is `@aws-sdk/fetch-http-handler`,
|
|
12
|
+
which is the default.
|
|
13
|
+
This alternative has only been tested against `S3` in browsers.
|
|
14
|
+
|
|
15
|
+
## Polyfills
|
|
16
|
+
|
|
17
|
+
The following global-scope implementations are accessed by this package:
|
|
18
|
+
|
|
19
|
+
- `XMLHttpRequest`
|
|
20
|
+
- `TextEncoder`
|
|
21
|
+
- `TransformStream`
|
|
22
|
+
- `Blob`
|
|
23
|
+
|
|
24
|
+
You will have to supply polyfills, for example for `TextEncoder` and `TransformStream`, for environments
|
|
25
|
+
that do not implement them natively.
|
|
26
|
+
|
|
27
|
+
### Use case: XMLHttpRequest upload progress events
|
|
28
|
+
|
|
29
|
+
Use the `Upload` class from the `@aws-sdk/lib-storage` package as normal, except supplying a different
|
|
30
|
+
`HttpHandler` when creating the `S3Client` or `S3` object(s).
|
|
31
|
+
|
|
32
|
+
See also: [lib-storage/README.md](https://github.com/aws/aws-sdk-js-v3/blob/main/lib/lib-storage/README.md).
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
import { XhrHttpHandler } from "@aws-sdk/xhr-http-handler";
|
|
36
|
+
import { S3Client } from "@aws-sdk/client-s3";
|
|
37
|
+
import { Upload } from "@aws-sdk/lib-storage";
|
|
38
|
+
|
|
39
|
+
const client = new S3Client({
|
|
40
|
+
requestHandler: new XhrHttpHandler({}), // overrides default FetchHttpHandler in browsers.
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const upload = new Upload({
|
|
44
|
+
client,
|
|
45
|
+
params: {
|
|
46
|
+
/* ... */
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
upload.on("httpUploadProgress", (progress) => {
|
|
51
|
+
// Note, this event will be emitted much more frequently when using the XhrHttpHandler.
|
|
52
|
+
// Your application should be ready to throttle the event listener if it is
|
|
53
|
+
// computationally expensive.
|
|
54
|
+
|
|
55
|
+
// The default FetchHttpHandler only emits this event upon the completion of each
|
|
56
|
+
// part, a minimum of 5 MB. Using XHR will emit this event continuously, including
|
|
57
|
+
// for files smaller than the chunk size, which use single-part upload.
|
|
58
|
+
console.log(progress);
|
|
59
|
+
|
|
60
|
+
console.log(
|
|
61
|
+
progress.loaded, // Bytes uploaded so far.
|
|
62
|
+
progress.total // Total bytes. Divide these two for progress percentage.
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const completeMultiPartUpload = await upload.done();
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Use case: XMLHttpRequest download progress and other events
|
|
70
|
+
|
|
71
|
+
`XhrHttpHandler` extends `EventEmitter`.
|
|
72
|
+
|
|
73
|
+
##### Download progress
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
import { XhrHttpHandler } from "@aws-sdk/xhr-http-handler";
|
|
77
|
+
import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3";
|
|
78
|
+
|
|
79
|
+
const handler = new XhrHttpHandler({});
|
|
80
|
+
|
|
81
|
+
handler.on(XhrHttpHandler.EVENTS.PROGRESS, (progress, request) => {
|
|
82
|
+
if (progress.lengthComputable) {
|
|
83
|
+
console.log(
|
|
84
|
+
progress.loaded, // bytes
|
|
85
|
+
progress.total, // bytes
|
|
86
|
+
);
|
|
87
|
+
console.log(
|
|
88
|
+
request // contains the request information to differentiate
|
|
89
|
+
// requests from the same handler.
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const client = new S3Client({
|
|
95
|
+
requestHandler: handler,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
await client.send(new GetObjectCommand(/*...*/));
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
##### Accessing the `XMLHttpRequest` object.
|
|
102
|
+
|
|
103
|
+
You can access the `XMLHttpRequest` object to inspect it or to
|
|
104
|
+
attach addiional event listeners.
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
import { XhrHttpHandler } from "@aws-sdk/xhr-http-handler";
|
|
108
|
+
import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3";
|
|
109
|
+
|
|
110
|
+
const handler = new XhrHttpHandler({});
|
|
111
|
+
|
|
112
|
+
handler.on(XhrHttpHandler.EVENTS.XHR_INSTANTIATED, (xhr) => {
|
|
113
|
+
// a new XMLHttpRequest is created for each command sent.
|
|
114
|
+
// this is immediately after instantiation.
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
handler.on(XhrHttpHandler.EVENTS.BEFORE_XHR_SEND, (xhr) => {
|
|
118
|
+
// a new XMLHttpRequest is created for each command sent.
|
|
119
|
+
// this is immediately before calling `xhr.send(body)`.
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const client = new S3Client({
|
|
123
|
+
requestHandler: handler,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
await client.send(new GetObjectCommand(/*...*/));
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
You can check the source `.ts` file or published `.d.ts` file
|
|
130
|
+
for the full list of events, or inspect the `XhrHttpHandler.EVENTS`
|
|
131
|
+
object at runtime.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requestTimeout = void 0;
|
|
4
|
+
const requestTimeout = (timeoutInMs = 0) => new Promise((resolve, reject) => {
|
|
5
|
+
if (timeoutInMs) {
|
|
6
|
+
setTimeout(() => {
|
|
7
|
+
const timeoutError = new Error(`Request did not complete within ${timeoutInMs} ms`);
|
|
8
|
+
timeoutError.name = "TimeoutError";
|
|
9
|
+
reject(timeoutError);
|
|
10
|
+
}, timeoutInMs);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
exports.requestTimeout = requestTimeout;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.XhrHttpHandler = void 0;
|
|
4
|
+
const protocol_http_1 = require("@aws-sdk/protocol-http");
|
|
5
|
+
const querystring_builder_1 = require("@aws-sdk/querystring-builder");
|
|
6
|
+
const events_1 = require("events");
|
|
7
|
+
const request_timeout_1 = require("./request-timeout");
|
|
8
|
+
const EVENTS = {
|
|
9
|
+
get PROGRESS() {
|
|
10
|
+
return "xhr.progress";
|
|
11
|
+
},
|
|
12
|
+
get UPLOAD_PROGRESS() {
|
|
13
|
+
return "xhr.upload.progress";
|
|
14
|
+
},
|
|
15
|
+
get XHR_INSTANTIATED() {
|
|
16
|
+
return "after.xhr.new";
|
|
17
|
+
},
|
|
18
|
+
get BEFORE_XHR_SEND() {
|
|
19
|
+
return "before.xhr.send";
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
class XhrHttpHandler extends events_1.EventEmitter {
|
|
23
|
+
constructor(options) {
|
|
24
|
+
super();
|
|
25
|
+
if (typeof options === "function") {
|
|
26
|
+
this.configProvider = options();
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
this.config = options !== null && options !== void 0 ? options : {};
|
|
30
|
+
this.configProvider = Promise.resolve(this.config);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
destroy() {
|
|
34
|
+
}
|
|
35
|
+
async handle(request, { abortSignal } = {}) {
|
|
36
|
+
if (!this.config) {
|
|
37
|
+
this.config = await this.configProvider;
|
|
38
|
+
}
|
|
39
|
+
const requestTimeoutInMs = Number(this.config.requestTimeout) | 0;
|
|
40
|
+
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
|
|
41
|
+
const abortError = new Error("Request aborted");
|
|
42
|
+
abortError.name = "AbortError";
|
|
43
|
+
throw abortError;
|
|
44
|
+
}
|
|
45
|
+
let path = request.path;
|
|
46
|
+
if (request.query) {
|
|
47
|
+
const queryString = (0, querystring_builder_1.buildQueryString)(request.query);
|
|
48
|
+
if (queryString) {
|
|
49
|
+
path += `?${queryString}`;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const { port, method } = request;
|
|
53
|
+
const url = `${request.protocol}//${request.hostname}${port ? `:${port}` : ""}${path}`;
|
|
54
|
+
const body = method === "GET" || method === "HEAD" ? undefined : request.body;
|
|
55
|
+
const xhr = new XMLHttpRequest();
|
|
56
|
+
this.emit(EVENTS.XHR_INSTANTIATED, xhr);
|
|
57
|
+
const raceOfPromises = [
|
|
58
|
+
new Promise((resolve, reject) => {
|
|
59
|
+
let streamCursor = 0;
|
|
60
|
+
let stream;
|
|
61
|
+
let writer;
|
|
62
|
+
xhr.upload.addEventListener("progress", (event) => {
|
|
63
|
+
this.emit(XhrHttpHandler.EVENTS.UPLOAD_PROGRESS, event, request);
|
|
64
|
+
});
|
|
65
|
+
xhr.addEventListener("progress", (event) => {
|
|
66
|
+
this.emit(XhrHttpHandler.EVENTS.PROGRESS, event, request);
|
|
67
|
+
});
|
|
68
|
+
xhr.addEventListener("error", reject);
|
|
69
|
+
xhr.addEventListener("timeout", () => {
|
|
70
|
+
reject(new Error("XMLHttpRequest timed out."));
|
|
71
|
+
});
|
|
72
|
+
xhr.addEventListener("readystatechange", () => {
|
|
73
|
+
const isArrayBuffer = xhr.responseType === "arraybuffer" && xhr.response;
|
|
74
|
+
const isText = !isArrayBuffer && typeof xhr.responseText === "string";
|
|
75
|
+
if (isText && !stream) {
|
|
76
|
+
({ stream, writer } = this.initializeTransformStream());
|
|
77
|
+
}
|
|
78
|
+
switch (xhr.readyState) {
|
|
79
|
+
case XMLHttpRequest.LOADING:
|
|
80
|
+
if (isText) {
|
|
81
|
+
writer.write(streamCursor > 0 ? xhr.responseText.slice(streamCursor) : xhr.responseText);
|
|
82
|
+
streamCursor = xhr.responseText.length;
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
case XMLHttpRequest.DONE:
|
|
86
|
+
const body = (() => {
|
|
87
|
+
if (isArrayBuffer) {
|
|
88
|
+
return new Blob([xhr.response]);
|
|
89
|
+
}
|
|
90
|
+
if (isText) {
|
|
91
|
+
writer.releaseLock();
|
|
92
|
+
stream.writable.close();
|
|
93
|
+
return stream.readable;
|
|
94
|
+
}
|
|
95
|
+
reject(new Error(`Unexpected XHR response type ${xhr.responseType}. Expected string or arraybuffer.`));
|
|
96
|
+
})();
|
|
97
|
+
resolve({
|
|
98
|
+
response: new protocol_http_1.HttpResponse({
|
|
99
|
+
headers: this.responseHeaders(xhr.getAllResponseHeaders()),
|
|
100
|
+
statusCode: xhr.status,
|
|
101
|
+
body,
|
|
102
|
+
}),
|
|
103
|
+
});
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
xhr.open(method, url);
|
|
108
|
+
for (const [header, value] of Object.entries(request.headers)) {
|
|
109
|
+
if (!isForbiddenRequestHeader(header)) {
|
|
110
|
+
xhr.setRequestHeader(header, value);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
this.emit(EVENTS.BEFORE_XHR_SEND, xhr);
|
|
114
|
+
xhr.send(body);
|
|
115
|
+
}),
|
|
116
|
+
(0, request_timeout_1.requestTimeout)(requestTimeoutInMs),
|
|
117
|
+
];
|
|
118
|
+
if (abortSignal) {
|
|
119
|
+
raceOfPromises.push(new Promise((resolve, reject) => {
|
|
120
|
+
abortSignal.onabort = () => {
|
|
121
|
+
xhr.abort();
|
|
122
|
+
const abortError = new Error("Request aborted");
|
|
123
|
+
abortError.name = "AbortError";
|
|
124
|
+
reject(abortError);
|
|
125
|
+
};
|
|
126
|
+
}));
|
|
127
|
+
}
|
|
128
|
+
return Promise.race(raceOfPromises);
|
|
129
|
+
}
|
|
130
|
+
responseHeaders(xhrHeaders) {
|
|
131
|
+
if (!xhrHeaders) {
|
|
132
|
+
return {};
|
|
133
|
+
}
|
|
134
|
+
return xhrHeaders.split("\r\n").reduce((headerMap, line) => {
|
|
135
|
+
const parts = line.split(": ");
|
|
136
|
+
const header = parts.shift();
|
|
137
|
+
const value = parts.join(": ");
|
|
138
|
+
headerMap[header] = value;
|
|
139
|
+
return headerMap;
|
|
140
|
+
}, {});
|
|
141
|
+
}
|
|
142
|
+
initializeTransformStream() {
|
|
143
|
+
const textEncoder = new TextEncoder();
|
|
144
|
+
const stream = new TransformStream({
|
|
145
|
+
start() { },
|
|
146
|
+
async transform(chunk, controller) {
|
|
147
|
+
controller.enqueue(textEncoder.encode(String(chunk)));
|
|
148
|
+
},
|
|
149
|
+
flush() { },
|
|
150
|
+
});
|
|
151
|
+
const writer = stream.writable.getWriter();
|
|
152
|
+
return {
|
|
153
|
+
stream,
|
|
154
|
+
writer,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.XhrHttpHandler = XhrHttpHandler;
|
|
159
|
+
XhrHttpHandler.EVENTS = EVENTS;
|
|
160
|
+
const isForbiddenRequestHeader = (header) => {
|
|
161
|
+
header = header.toLowerCase();
|
|
162
|
+
if (header.startsWith("proxy-")) {
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
if (header.startsWith("sec-")) {
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
return forbiddenHeaders.includes(header);
|
|
169
|
+
};
|
|
170
|
+
const forbiddenHeaders = [
|
|
171
|
+
"Accept-Charset",
|
|
172
|
+
"Accept-Encoding",
|
|
173
|
+
"Access-Control-Request-Headers",
|
|
174
|
+
"Access-Control-Request-Method",
|
|
175
|
+
"Connection",
|
|
176
|
+
"Content-Length",
|
|
177
|
+
"Cookie",
|
|
178
|
+
"Date",
|
|
179
|
+
"DNT",
|
|
180
|
+
"Expect",
|
|
181
|
+
"Feature-Policy",
|
|
182
|
+
"Host",
|
|
183
|
+
"Keep-Alive",
|
|
184
|
+
"Origin",
|
|
185
|
+
"Referer",
|
|
186
|
+
"TE",
|
|
187
|
+
"Trailer",
|
|
188
|
+
"Transfer-Encoding",
|
|
189
|
+
"Upgrade",
|
|
190
|
+
"Via",
|
|
191
|
+
].map((_) => _.toLowerCase());
|
package/dist-es/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./xhr-http-handler";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export var requestTimeout = function (timeoutInMs) {
|
|
2
|
+
if (timeoutInMs === void 0) { timeoutInMs = 0; }
|
|
3
|
+
return new Promise(function (resolve, reject) {
|
|
4
|
+
if (timeoutInMs) {
|
|
5
|
+
setTimeout(function () {
|
|
6
|
+
var timeoutError = new Error("Request did not complete within ".concat(timeoutInMs, " ms"));
|
|
7
|
+
timeoutError.name = "TimeoutError";
|
|
8
|
+
reject(timeoutError);
|
|
9
|
+
}, timeoutInMs);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
};
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { __awaiter, __extends, __generator, __read, __values } from "tslib";
|
|
2
|
+
import { HttpResponse } from "@aws-sdk/protocol-http";
|
|
3
|
+
import { buildQueryString } from "@aws-sdk/querystring-builder";
|
|
4
|
+
import { EventEmitter } from "events";
|
|
5
|
+
import { requestTimeout } from "./request-timeout";
|
|
6
|
+
var EVENTS = {
|
|
7
|
+
get PROGRESS() {
|
|
8
|
+
return "xhr.progress";
|
|
9
|
+
},
|
|
10
|
+
get UPLOAD_PROGRESS() {
|
|
11
|
+
return "xhr.upload.progress";
|
|
12
|
+
},
|
|
13
|
+
get XHR_INSTANTIATED() {
|
|
14
|
+
return "after.xhr.new";
|
|
15
|
+
},
|
|
16
|
+
get BEFORE_XHR_SEND() {
|
|
17
|
+
return "before.xhr.send";
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
var XhrHttpHandler = (function (_super) {
|
|
21
|
+
__extends(XhrHttpHandler, _super);
|
|
22
|
+
function XhrHttpHandler(options) {
|
|
23
|
+
var _this = _super.call(this) || this;
|
|
24
|
+
if (typeof options === "function") {
|
|
25
|
+
_this.configProvider = options();
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
_this.config = options !== null && options !== void 0 ? options : {};
|
|
29
|
+
_this.configProvider = Promise.resolve(_this.config);
|
|
30
|
+
}
|
|
31
|
+
return _this;
|
|
32
|
+
}
|
|
33
|
+
XhrHttpHandler.prototype.destroy = function () {
|
|
34
|
+
};
|
|
35
|
+
XhrHttpHandler.prototype.handle = function (request, _a) {
|
|
36
|
+
var _b = _a === void 0 ? {} : _a, abortSignal = _b.abortSignal;
|
|
37
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
38
|
+
var _c, requestTimeoutInMs, abortError, path, queryString, port, method, url, body, xhr, raceOfPromises;
|
|
39
|
+
var _this = this;
|
|
40
|
+
return __generator(this, function (_d) {
|
|
41
|
+
switch (_d.label) {
|
|
42
|
+
case 0:
|
|
43
|
+
if (!!this.config) return [3, 2];
|
|
44
|
+
_c = this;
|
|
45
|
+
return [4, this.configProvider];
|
|
46
|
+
case 1:
|
|
47
|
+
_c.config = _d.sent();
|
|
48
|
+
_d.label = 2;
|
|
49
|
+
case 2:
|
|
50
|
+
requestTimeoutInMs = Number(this.config.requestTimeout) | 0;
|
|
51
|
+
if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
|
|
52
|
+
abortError = new Error("Request aborted");
|
|
53
|
+
abortError.name = "AbortError";
|
|
54
|
+
throw abortError;
|
|
55
|
+
}
|
|
56
|
+
path = request.path;
|
|
57
|
+
if (request.query) {
|
|
58
|
+
queryString = buildQueryString(request.query);
|
|
59
|
+
if (queryString) {
|
|
60
|
+
path += "?".concat(queryString);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
port = request.port, method = request.method;
|
|
64
|
+
url = "".concat(request.protocol, "//").concat(request.hostname).concat(port ? ":".concat(port) : "").concat(path);
|
|
65
|
+
body = method === "GET" || method === "HEAD" ? undefined : request.body;
|
|
66
|
+
xhr = new XMLHttpRequest();
|
|
67
|
+
this.emit(EVENTS.XHR_INSTANTIATED, xhr);
|
|
68
|
+
raceOfPromises = [
|
|
69
|
+
new Promise(function (resolve, reject) {
|
|
70
|
+
var e_1, _a;
|
|
71
|
+
var streamCursor = 0;
|
|
72
|
+
var stream;
|
|
73
|
+
var writer;
|
|
74
|
+
xhr.upload.addEventListener("progress", function (event) {
|
|
75
|
+
_this.emit(XhrHttpHandler.EVENTS.UPLOAD_PROGRESS, event, request);
|
|
76
|
+
});
|
|
77
|
+
xhr.addEventListener("progress", function (event) {
|
|
78
|
+
_this.emit(XhrHttpHandler.EVENTS.PROGRESS, event, request);
|
|
79
|
+
});
|
|
80
|
+
xhr.addEventListener("error", reject);
|
|
81
|
+
xhr.addEventListener("timeout", function () {
|
|
82
|
+
reject(new Error("XMLHttpRequest timed out."));
|
|
83
|
+
});
|
|
84
|
+
xhr.addEventListener("readystatechange", function () {
|
|
85
|
+
var _a;
|
|
86
|
+
var isArrayBuffer = xhr.responseType === "arraybuffer" && xhr.response;
|
|
87
|
+
var isText = !isArrayBuffer && typeof xhr.responseText === "string";
|
|
88
|
+
if (isText && !stream) {
|
|
89
|
+
(_a = _this.initializeTransformStream(), stream = _a.stream, writer = _a.writer);
|
|
90
|
+
}
|
|
91
|
+
switch (xhr.readyState) {
|
|
92
|
+
case XMLHttpRequest.LOADING:
|
|
93
|
+
if (isText) {
|
|
94
|
+
writer.write(streamCursor > 0 ? xhr.responseText.slice(streamCursor) : xhr.responseText);
|
|
95
|
+
streamCursor = xhr.responseText.length;
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
case XMLHttpRequest.DONE:
|
|
99
|
+
var body_1 = (function () {
|
|
100
|
+
if (isArrayBuffer) {
|
|
101
|
+
return new Blob([xhr.response]);
|
|
102
|
+
}
|
|
103
|
+
if (isText) {
|
|
104
|
+
writer.releaseLock();
|
|
105
|
+
stream.writable.close();
|
|
106
|
+
return stream.readable;
|
|
107
|
+
}
|
|
108
|
+
reject(new Error("Unexpected XHR response type ".concat(xhr.responseType, ". Expected string or arraybuffer.")));
|
|
109
|
+
})();
|
|
110
|
+
resolve({
|
|
111
|
+
response: new HttpResponse({
|
|
112
|
+
headers: _this.responseHeaders(xhr.getAllResponseHeaders()),
|
|
113
|
+
statusCode: xhr.status,
|
|
114
|
+
body: body_1,
|
|
115
|
+
}),
|
|
116
|
+
});
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
xhr.open(method, url);
|
|
121
|
+
try {
|
|
122
|
+
for (var _b = __values(Object.entries(request.headers)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
123
|
+
var _d = __read(_c.value, 2), header = _d[0], value = _d[1];
|
|
124
|
+
if (!isForbiddenRequestHeader(header)) {
|
|
125
|
+
xhr.setRequestHeader(header, value);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
130
|
+
finally {
|
|
131
|
+
try {
|
|
132
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
133
|
+
}
|
|
134
|
+
finally { if (e_1) throw e_1.error; }
|
|
135
|
+
}
|
|
136
|
+
_this.emit(EVENTS.BEFORE_XHR_SEND, xhr);
|
|
137
|
+
xhr.send(body);
|
|
138
|
+
}),
|
|
139
|
+
requestTimeout(requestTimeoutInMs),
|
|
140
|
+
];
|
|
141
|
+
if (abortSignal) {
|
|
142
|
+
raceOfPromises.push(new Promise(function (resolve, reject) {
|
|
143
|
+
abortSignal.onabort = function () {
|
|
144
|
+
xhr.abort();
|
|
145
|
+
var abortError = new Error("Request aborted");
|
|
146
|
+
abortError.name = "AbortError";
|
|
147
|
+
reject(abortError);
|
|
148
|
+
};
|
|
149
|
+
}));
|
|
150
|
+
}
|
|
151
|
+
return [2, Promise.race(raceOfPromises)];
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
};
|
|
156
|
+
XhrHttpHandler.prototype.responseHeaders = function (xhrHeaders) {
|
|
157
|
+
if (!xhrHeaders) {
|
|
158
|
+
return {};
|
|
159
|
+
}
|
|
160
|
+
return xhrHeaders.split("\r\n").reduce(function (headerMap, line) {
|
|
161
|
+
var parts = line.split(": ");
|
|
162
|
+
var header = parts.shift();
|
|
163
|
+
var value = parts.join(": ");
|
|
164
|
+
headerMap[header] = value;
|
|
165
|
+
return headerMap;
|
|
166
|
+
}, {});
|
|
167
|
+
};
|
|
168
|
+
XhrHttpHandler.prototype.initializeTransformStream = function () {
|
|
169
|
+
var textEncoder = new TextEncoder();
|
|
170
|
+
var stream = new TransformStream({
|
|
171
|
+
start: function () { },
|
|
172
|
+
transform: function (chunk, controller) {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
174
|
+
return __generator(this, function (_a) {
|
|
175
|
+
controller.enqueue(textEncoder.encode(String(chunk)));
|
|
176
|
+
return [2];
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
},
|
|
180
|
+
flush: function () { },
|
|
181
|
+
});
|
|
182
|
+
var writer = stream.writable.getWriter();
|
|
183
|
+
return {
|
|
184
|
+
stream: stream,
|
|
185
|
+
writer: writer,
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
XhrHttpHandler.EVENTS = EVENTS;
|
|
189
|
+
return XhrHttpHandler;
|
|
190
|
+
}(EventEmitter));
|
|
191
|
+
export { XhrHttpHandler };
|
|
192
|
+
var isForbiddenRequestHeader = function (header) {
|
|
193
|
+
header = header.toLowerCase();
|
|
194
|
+
if (header.startsWith("proxy-")) {
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
if (header.startsWith("sec-")) {
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
return forbiddenHeaders.includes(header);
|
|
201
|
+
};
|
|
202
|
+
var forbiddenHeaders = [
|
|
203
|
+
"Accept-Charset",
|
|
204
|
+
"Accept-Encoding",
|
|
205
|
+
"Access-Control-Request-Headers",
|
|
206
|
+
"Access-Control-Request-Method",
|
|
207
|
+
"Connection",
|
|
208
|
+
"Content-Length",
|
|
209
|
+
"Cookie",
|
|
210
|
+
"Date",
|
|
211
|
+
"DNT",
|
|
212
|
+
"Expect",
|
|
213
|
+
"Feature-Policy",
|
|
214
|
+
"Host",
|
|
215
|
+
"Keep-Alive",
|
|
216
|
+
"Origin",
|
|
217
|
+
"Referer",
|
|
218
|
+
"TE",
|
|
219
|
+
"Trailer",
|
|
220
|
+
"Transfer-Encoding",
|
|
221
|
+
"Upgrade",
|
|
222
|
+
"Via",
|
|
223
|
+
].map(function (_) { return _.toLowerCase(); });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./xhr-http-handler";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const requestTimeout: (timeoutInMs?: number) => Promise<never>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./xhr-http-handler";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const requestTimeout: (timeoutInMs?: number) => Promise<never>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
import { HttpHandler, HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
|
|
3
|
+
import { HttpHandlerOptions, Provider } from "@aws-sdk/types";
|
|
4
|
+
import { EventEmitter } from "events";
|
|
5
|
+
|
|
6
|
+
export interface XhrHttpHandlerOptions {
|
|
7
|
+
|
|
8
|
+
requestTimeout?: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export declare type XhrHttpHandlerEvents = {
|
|
12
|
+
|
|
13
|
+
readonly PROGRESS: "xhr.progress";
|
|
14
|
+
|
|
15
|
+
readonly UPLOAD_PROGRESS: "xhr.upload.progress";
|
|
16
|
+
|
|
17
|
+
readonly XHR_INSTANTIATED: "after.xhr.new";
|
|
18
|
+
|
|
19
|
+
readonly BEFORE_XHR_SEND: "before.xhr.send";
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export declare class XhrHttpHandler extends EventEmitter implements HttpHandler {
|
|
23
|
+
static readonly EVENTS: XhrHttpHandlerEvents;
|
|
24
|
+
private config?;
|
|
25
|
+
private readonly configProvider;
|
|
26
|
+
constructor(options?: XhrHttpHandlerOptions | Provider<XhrHttpHandlerOptions>);
|
|
27
|
+
destroy(): void;
|
|
28
|
+
handle(request: HttpRequest, { abortSignal }?: HttpHandlerOptions): Promise<{
|
|
29
|
+
response: HttpResponse;
|
|
30
|
+
}>;
|
|
31
|
+
|
|
32
|
+
private responseHeaders;
|
|
33
|
+
|
|
34
|
+
private initializeTransformStream;
|
|
35
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { HttpHandler, HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
|
|
3
|
+
import { HttpHandlerOptions, Provider } from "@aws-sdk/types";
|
|
4
|
+
import { EventEmitter } from "events";
|
|
5
|
+
/**
|
|
6
|
+
* Represents the http options that can be passed to the xhr http client.
|
|
7
|
+
*/
|
|
8
|
+
export interface XhrHttpHandlerOptions {
|
|
9
|
+
/**
|
|
10
|
+
* The number of milliseconds a request can take before being automatically
|
|
11
|
+
* terminated.
|
|
12
|
+
*/
|
|
13
|
+
requestTimeout?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Events emitted by the XhrHttpHandler class as an EventEmitter.
|
|
17
|
+
*/
|
|
18
|
+
export declare type XhrHttpHandlerEvents = {
|
|
19
|
+
/**
|
|
20
|
+
* Emitted for xhr on progress.
|
|
21
|
+
* Payload is the native ProgressEvent and the HttpRequest to allow
|
|
22
|
+
* differentiation of multiple concurrent request events.
|
|
23
|
+
*/
|
|
24
|
+
readonly PROGRESS: "xhr.progress";
|
|
25
|
+
/**
|
|
26
|
+
* Emitted for xhr.upload on progress.
|
|
27
|
+
* Payload is the native ProgressEvent and the HttpRequest to allow
|
|
28
|
+
* differentiation of multiple concurrent request events.
|
|
29
|
+
*/
|
|
30
|
+
readonly UPLOAD_PROGRESS: "xhr.upload.progress";
|
|
31
|
+
/**
|
|
32
|
+
* Emits with the xhr object after it is instantiated with new.
|
|
33
|
+
* You can attach additional custom event listeners at this point.
|
|
34
|
+
*/
|
|
35
|
+
readonly XHR_INSTANTIATED: "after.xhr.new";
|
|
36
|
+
/**
|
|
37
|
+
* Emits with the xhr object before the send method is called on it.
|
|
38
|
+
* You can attach additional custom event listeners at this point.
|
|
39
|
+
*/
|
|
40
|
+
readonly BEFORE_XHR_SEND: "before.xhr.send";
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* An implementation of HttpHandler that uses XMLHttpRequest, which is
|
|
44
|
+
* traditionally associated with browsers.
|
|
45
|
+
*/
|
|
46
|
+
export declare class XhrHttpHandler extends EventEmitter implements HttpHandler {
|
|
47
|
+
static readonly EVENTS: XhrHttpHandlerEvents;
|
|
48
|
+
private config?;
|
|
49
|
+
private readonly configProvider;
|
|
50
|
+
constructor(options?: XhrHttpHandlerOptions | Provider<XhrHttpHandlerOptions>);
|
|
51
|
+
destroy(): void;
|
|
52
|
+
handle(request: HttpRequest, { abortSignal }?: HttpHandlerOptions): Promise<{
|
|
53
|
+
response: HttpResponse;
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* Converts XHR response headers to a map.
|
|
57
|
+
* @param xhrHeaders - string to be parsed.
|
|
58
|
+
*/
|
|
59
|
+
private responseHeaders;
|
|
60
|
+
/**
|
|
61
|
+
* @returns a stream and its default writer to be used to map the xhr response text to a readable stream.
|
|
62
|
+
*/
|
|
63
|
+
private initializeTransformStream;
|
|
64
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aws-sdk/xhr-http-handler",
|
|
3
|
+
"version": "3.131.0",
|
|
4
|
+
"description": "Provides a way to make requests using XMLHttpRequest",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
7
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
8
|
+
"build:es": "tsc -p tsconfig.es.json",
|
|
9
|
+
"build:types": "tsc -p tsconfig.types.json",
|
|
10
|
+
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
|
|
11
|
+
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
|
|
12
|
+
"test": "jest --coverage"
|
|
13
|
+
},
|
|
14
|
+
"author": "AWS SDK for JavaScript Team (https://aws.amazon.com/javascript/)",
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"main": "./dist-cjs/index.js",
|
|
17
|
+
"module": "./dist-es/index.js",
|
|
18
|
+
"types": "./dist-types/index.d.ts",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@aws-sdk/protocol-http": "3.127.0",
|
|
21
|
+
"@aws-sdk/querystring-builder": "3.127.0",
|
|
22
|
+
"@aws-sdk/types": "3.127.0",
|
|
23
|
+
"@aws-sdk/util-base64-browser": "3.109.0",
|
|
24
|
+
"events": "3.3.0",
|
|
25
|
+
"tslib": "^2.3.1"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@aws-sdk/abort-controller": "3.127.0",
|
|
29
|
+
"@tsconfig/recommended": "1.0.1",
|
|
30
|
+
"concurrently": "7.0.0",
|
|
31
|
+
"downlevel-dts": "0.7.0",
|
|
32
|
+
"rimraf": "3.0.2",
|
|
33
|
+
"typedoc": "0.19.2",
|
|
34
|
+
"typescript": "~4.6.2"
|
|
35
|
+
},
|
|
36
|
+
"typesVersions": {
|
|
37
|
+
"<4.0": {
|
|
38
|
+
"dist-types/*": [
|
|
39
|
+
"dist-types/ts3.4/*"
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"dist-*"
|
|
45
|
+
],
|
|
46
|
+
"homepage": "https://github.com/aws/aws-sdk-js-v3/tree/main/packages/xhr-http-handler",
|
|
47
|
+
"repository": {
|
|
48
|
+
"type": "git",
|
|
49
|
+
"url": "git+https://github.com/aws/aws-sdk-js-v3.git",
|
|
50
|
+
"directory": "packages/xhr-http-handler"
|
|
51
|
+
},
|
|
52
|
+
"bugs": {
|
|
53
|
+
"url": "https://github.com/aws/aws-sdk-js-v3/issues"
|
|
54
|
+
}
|
|
55
|
+
}
|