@aws-sdk/middleware-sdk-s3 3.614.0 → 3.617.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/dist-cjs/index.js
CHANGED
|
@@ -441,25 +441,46 @@ var resolveS3Config = /* @__PURE__ */ __name((input, {
|
|
|
441
441
|
|
|
442
442
|
// src/throw-200-exceptions.ts
|
|
443
443
|
|
|
444
|
-
var
|
|
444
|
+
var import_util_stream = require("@smithy/util-stream");
|
|
445
|
+
var THROW_IF_EMPTY_BODY = {
|
|
446
|
+
CopyObjectCommand: true,
|
|
447
|
+
UploadPartCopyCommand: true,
|
|
448
|
+
CompleteMultipartUploadCommand: true
|
|
449
|
+
};
|
|
450
|
+
var MAX_BYTES_TO_INSPECT = 3e3;
|
|
451
|
+
var throw200ExceptionsMiddleware = /* @__PURE__ */ __name((config) => (next, context) => async (args) => {
|
|
445
452
|
const result = await next(args);
|
|
446
453
|
const { response } = result;
|
|
447
|
-
if (!import_protocol_http.HttpResponse.isInstance(response))
|
|
454
|
+
if (!import_protocol_http.HttpResponse.isInstance(response)) {
|
|
448
455
|
return result;
|
|
449
|
-
|
|
450
|
-
|
|
456
|
+
}
|
|
457
|
+
const { statusCode, body: sourceBody } = response;
|
|
458
|
+
if (statusCode < 200 || statusCode >= 300) {
|
|
451
459
|
return result;
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
460
|
+
}
|
|
461
|
+
let bodyCopy = sourceBody;
|
|
462
|
+
let body = sourceBody;
|
|
463
|
+
if (sourceBody && typeof sourceBody === "object" && !(sourceBody instanceof Uint8Array)) {
|
|
464
|
+
[bodyCopy, body] = await (0, import_util_stream.splitStream)(sourceBody);
|
|
465
|
+
}
|
|
466
|
+
response.body = body;
|
|
467
|
+
const bodyBytes = await collectBody(bodyCopy, {
|
|
468
|
+
streamCollector: async (stream) => {
|
|
469
|
+
return (0, import_util_stream.headStream)(stream, MAX_BYTES_TO_INSPECT);
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
if (typeof (bodyCopy == null ? void 0 : bodyCopy.destroy) === "function") {
|
|
473
|
+
bodyCopy.destroy();
|
|
474
|
+
}
|
|
475
|
+
const bodyStringTail = config.utf8Encoder(bodyBytes.subarray(bodyBytes.length - 16));
|
|
476
|
+
if (bodyBytes.length === 0 && THROW_IF_EMPTY_BODY[context.commandName]) {
|
|
455
477
|
const err = new Error("S3 aborted request");
|
|
456
478
|
err.name = "InternalError";
|
|
457
479
|
throw err;
|
|
458
480
|
}
|
|
459
|
-
if (
|
|
481
|
+
if (bodyStringTail && bodyStringTail.endsWith("</Error>")) {
|
|
460
482
|
response.statusCode = 400;
|
|
461
483
|
}
|
|
462
|
-
response.body = bodyBytes;
|
|
463
484
|
return result;
|
|
464
485
|
}, "throw200ExceptionsMiddleware");
|
|
465
486
|
var collectBody = /* @__PURE__ */ __name((streamBody = new Uint8Array(), context) => {
|
|
@@ -468,7 +489,6 @@ var collectBody = /* @__PURE__ */ __name((streamBody = new Uint8Array(), context
|
|
|
468
489
|
}
|
|
469
490
|
return context.streamCollector(streamBody) || Promise.resolve(new Uint8Array());
|
|
470
491
|
}, "collectBody");
|
|
471
|
-
var collectBodyString = /* @__PURE__ */ __name((streamBody, context) => collectBody(streamBody, context).then((body) => context.utf8Encoder(body)), "collectBodyString");
|
|
472
492
|
var throw200ExceptionsMiddlewareOptions = {
|
|
473
493
|
relation: "after",
|
|
474
494
|
toMiddleware: "deserializerMiddleware",
|
|
@@ -1,23 +1,44 @@
|
|
|
1
1
|
import { HttpResponse } from "@smithy/protocol-http";
|
|
2
|
-
|
|
2
|
+
import { headStream, splitStream } from "@smithy/util-stream";
|
|
3
|
+
const THROW_IF_EMPTY_BODY = {
|
|
4
|
+
CopyObjectCommand: true,
|
|
5
|
+
UploadPartCopyCommand: true,
|
|
6
|
+
CompleteMultipartUploadCommand: true,
|
|
7
|
+
};
|
|
8
|
+
const MAX_BYTES_TO_INSPECT = 3000;
|
|
9
|
+
export const throw200ExceptionsMiddleware = (config) => (next, context) => async (args) => {
|
|
3
10
|
const result = await next(args);
|
|
4
11
|
const { response } = result;
|
|
5
|
-
if (!HttpResponse.isInstance(response))
|
|
12
|
+
if (!HttpResponse.isInstance(response)) {
|
|
6
13
|
return result;
|
|
7
|
-
|
|
8
|
-
|
|
14
|
+
}
|
|
15
|
+
const { statusCode, body: sourceBody } = response;
|
|
16
|
+
if (statusCode < 200 || statusCode >= 300) {
|
|
9
17
|
return result;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
18
|
+
}
|
|
19
|
+
let bodyCopy = sourceBody;
|
|
20
|
+
let body = sourceBody;
|
|
21
|
+
if (sourceBody && typeof sourceBody === "object" && !(sourceBody instanceof Uint8Array)) {
|
|
22
|
+
[bodyCopy, body] = await splitStream(sourceBody);
|
|
23
|
+
}
|
|
24
|
+
response.body = body;
|
|
25
|
+
const bodyBytes = await collectBody(bodyCopy, {
|
|
26
|
+
streamCollector: async (stream) => {
|
|
27
|
+
return headStream(stream, MAX_BYTES_TO_INSPECT);
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
if (typeof bodyCopy?.destroy === "function") {
|
|
31
|
+
bodyCopy.destroy();
|
|
32
|
+
}
|
|
33
|
+
const bodyStringTail = config.utf8Encoder(bodyBytes.subarray(bodyBytes.length - 16));
|
|
34
|
+
if (bodyBytes.length === 0 && THROW_IF_EMPTY_BODY[context.commandName]) {
|
|
13
35
|
const err = new Error("S3 aborted request");
|
|
14
36
|
err.name = "InternalError";
|
|
15
37
|
throw err;
|
|
16
38
|
}
|
|
17
|
-
if (
|
|
39
|
+
if (bodyStringTail && bodyStringTail.endsWith("</Error>")) {
|
|
18
40
|
response.statusCode = 400;
|
|
19
41
|
}
|
|
20
|
-
response.body = bodyBytes;
|
|
21
42
|
return result;
|
|
22
43
|
};
|
|
23
44
|
const collectBody = (streamBody = new Uint8Array(), context) => {
|
|
@@ -26,7 +47,6 @@ const collectBody = (streamBody = new Uint8Array(), context) => {
|
|
|
26
47
|
}
|
|
27
48
|
return context.streamCollector(streamBody) || Promise.resolve(new Uint8Array());
|
|
28
49
|
};
|
|
29
|
-
const collectBodyString = (streamBody, context) => collectBody(streamBody, context).then((body) => context.utf8Encoder(body));
|
|
30
50
|
export const throw200ExceptionsMiddlewareOptions = {
|
|
31
51
|
relation: "after",
|
|
32
52
|
toMiddleware: "deserializerMiddleware",
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { DeserializeMiddleware, Encoder, Pluggable, RelativeMiddlewareOptions
|
|
1
|
+
import { DeserializeMiddleware, Encoder, Pluggable, RelativeMiddlewareOptions } from "@smithy/types";
|
|
2
2
|
type PreviouslyResolved = {
|
|
3
|
-
streamCollector: StreamCollector;
|
|
4
3
|
utf8Encoder: Encoder;
|
|
5
4
|
};
|
|
6
5
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/middleware-sdk-s3",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.617.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
6
6
|
"build:cjs": "node ../../scripts/compilation/inline middleware-sdk-s3",
|
|
@@ -26,11 +26,13 @@
|
|
|
26
26
|
"@aws-sdk/types": "3.609.0",
|
|
27
27
|
"@aws-sdk/util-arn-parser": "3.568.0",
|
|
28
28
|
"@smithy/node-config-provider": "^3.1.4",
|
|
29
|
-
"@smithy/protocol-http": "^4.0.
|
|
30
|
-
"@smithy/signature-v4": "^
|
|
31
|
-
"@smithy/smithy-client": "^3.1.
|
|
29
|
+
"@smithy/protocol-http": "^4.0.4",
|
|
30
|
+
"@smithy/signature-v4": "^4.0.0",
|
|
31
|
+
"@smithy/smithy-client": "^3.1.8",
|
|
32
32
|
"@smithy/types": "^3.3.0",
|
|
33
33
|
"@smithy/util-config-provider": "^3.0.0",
|
|
34
|
+
"@smithy/util-stream": "^3.1.0",
|
|
35
|
+
"@smithy/util-utf8": "^3.0.0",
|
|
34
36
|
"tslib": "^2.6.2"
|
|
35
37
|
},
|
|
36
38
|
"devDependencies": {
|