@middy/http-content-encoding 7.0.2 → 7.1.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/README.md +2 -2
- package/index.d.ts +2 -0
- package/index.js +18 -4
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<p>
|
|
6
6
|
<a href="https://github.com/middyjs/middy/actions/workflows/test-unit.yml"><img src="https://github.com/middyjs/middy/actions/workflows/test-unit.yml/badge.svg" alt="GitHub Actions unit test status"></a>
|
|
7
7
|
<a href="https://github.com/middyjs/middy/actions/workflows/test-dast.yml"><img src="https://github.com/middyjs/middy/actions/workflows/test-dast.yml/badge.svg" alt="GitHub Actions dast test status"></a>
|
|
8
|
-
<a href="https://github.com/middyjs/middy/actions/workflows/test-perf.yml"><img src="https://github.com/middyjs/middy/actions/workflows/test-
|
|
8
|
+
<a href="https://github.com/middyjs/middy/actions/workflows/test-perf.yml"><img src="https://github.com/middyjs/middy/actions/workflows/test-perf.yml/badge.svg" alt="GitHub Actions perf test status"></a>
|
|
9
9
|
<a href="https://github.com/middyjs/middy/actions/workflows/test-sast.yml"><img src="https://github.com/middyjs/middy/actions/workflows/test-sast.yml/badge.svg" alt="GitHub Actions SAST test status"></a>
|
|
10
10
|
<a href="https://github.com/middyjs/middy/actions/workflows/test-lint.yml"><img src="https://github.com/middyjs/middy/actions/workflows/test-lint.yml/badge.svg" alt="GitHub Actions lint test status"></a>
|
|
11
11
|
<br/>
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
|
|
33
33
|
## License
|
|
34
34
|
|
|
35
|
-
Licensed under [MIT License](LICENSE). Copyright (c) 2017-
|
|
35
|
+
Licensed under [MIT License](LICENSE). Copyright (c) 2017-2026 [will Farrell](https://github.com/willfarrell), [Luciano Mammino](https://github.com/lmammino), and [Middy contributors](https://github.com/middyjs/middy/graphs/contributors).
|
|
36
36
|
|
|
37
37
|
<a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
|
|
38
38
|
<img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy.svg?type=large" alt="FOSSA Status" style="max-width:100%;">
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
// Copyright 2017 - 2026 will Farrell, Luciano Mammino, and Middy contributors.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
1
3
|
import { Readable } from "node:stream";
|
|
4
|
+
import { ReadableStream } from "node:stream/web";
|
|
2
5
|
|
|
3
6
|
import {
|
|
4
7
|
createBrotliCompress as brotliCompressStream,
|
|
@@ -49,6 +52,8 @@ const httpContentEncodingMiddleware = (opts) => {
|
|
|
49
52
|
}
|
|
50
53
|
const responseCacheControl =
|
|
51
54
|
response.headers["Cache-Control"] ?? response.headers["cache-control"];
|
|
55
|
+
const isNodeStream = response.body?._readableState;
|
|
56
|
+
const isWebStream = response.body instanceof ReadableStream;
|
|
52
57
|
if (
|
|
53
58
|
response.isBase64Encoded ||
|
|
54
59
|
!preferredEncoding ||
|
|
@@ -56,7 +61,8 @@ const httpContentEncodingMiddleware = (opts) => {
|
|
|
56
61
|
!response.body ||
|
|
57
62
|
(typeof response.body !== "string" &&
|
|
58
63
|
!Buffer.isBuffer(response.body) &&
|
|
59
|
-
!
|
|
64
|
+
!isNodeStream &&
|
|
65
|
+
!isWebStream) ||
|
|
60
66
|
responseCacheControl?.includes("no-transform")
|
|
61
67
|
) {
|
|
62
68
|
return;
|
|
@@ -76,13 +82,21 @@ const httpContentEncodingMiddleware = (opts) => {
|
|
|
76
82
|
}
|
|
77
83
|
|
|
78
84
|
// Support streamifyResponse
|
|
79
|
-
if (
|
|
85
|
+
if (isNodeStream || isWebStream) {
|
|
80
86
|
request.response.headers["Content-Encoding"] = contentEncoding;
|
|
81
|
-
|
|
87
|
+
if (isNodeStream) {
|
|
88
|
+
request.response.body = request.response.body.pipe(
|
|
89
|
+
contentEncodingStream,
|
|
90
|
+
);
|
|
91
|
+
} else if (isWebStream) {
|
|
92
|
+
request.response.body = Readable.toWeb(
|
|
93
|
+
Readable.fromWeb(response.body).pipe(contentEncodingStream),
|
|
94
|
+
);
|
|
95
|
+
}
|
|
82
96
|
addHeaderPart(response, "Vary", "Accept-Encoding");
|
|
83
97
|
return;
|
|
84
98
|
}
|
|
85
|
-
|
|
99
|
+
// isString
|
|
86
100
|
const stream = Readable.from(response.body).pipe(contentEncodingStream);
|
|
87
101
|
|
|
88
102
|
const chunks = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/http-content-encoding",
|
|
3
|
-
"version": "7.0
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "Http content encoding middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
13
|
"module": "./index.js",
|
|
14
|
+
"sideEffects": false,
|
|
14
15
|
"exports": {
|
|
15
16
|
".": {
|
|
16
17
|
"import": {
|
|
@@ -67,11 +68,11 @@
|
|
|
67
68
|
"url": "https://github.com/sponsors/willfarrell"
|
|
68
69
|
},
|
|
69
70
|
"dependencies": {
|
|
70
|
-
"@middy/util": "7.0
|
|
71
|
+
"@middy/util": "7.1.0"
|
|
71
72
|
},
|
|
72
73
|
"devDependencies": {
|
|
73
74
|
"@datastream/core": "0.0.42",
|
|
74
|
-
"@middy/core": "7.0
|
|
75
|
+
"@middy/core": "7.1.0"
|
|
75
76
|
},
|
|
76
77
|
"gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431"
|
|
77
78
|
}
|