@middy/http-content-encoding 5.0.2 → 5.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/index.js +1 -10
- package/package.json +4 -4
package/index.js
CHANGED
|
@@ -8,16 +8,11 @@ const contentEncodingStreams = {
|
|
|
8
8
|
};
|
|
9
9
|
const defaults = {
|
|
10
10
|
br: undefined,
|
|
11
|
-
// zstd: undefined,
|
|
12
11
|
gzip: undefined,
|
|
13
12
|
deflate: undefined,
|
|
14
13
|
overridePreferredEncoding: []
|
|
15
14
|
};
|
|
16
|
-
|
|
17
|
-
* `zstd` disabled due to lack of support in browsers
|
|
18
|
-
* https://github.com/Fyrd/caniuse/issues/4065
|
|
19
|
-
* https://github.com/andrew-aladev/brotli-vs-zstd
|
|
20
|
-
*/ const httpContentEncodingMiddleware = (opts)=>{
|
|
15
|
+
const httpContentEncodingMiddleware = (opts)=>{
|
|
21
16
|
const options = {
|
|
22
17
|
...defaults,
|
|
23
18
|
...opts
|
|
@@ -26,7 +21,6 @@ const defaults = {
|
|
|
26
21
|
const httpContentEncodingMiddlewareAfter = async (request)=>{
|
|
27
22
|
normalizeHttpResponse(request);
|
|
28
23
|
const { context: { preferredEncoding, preferredEncodings }, response } = request;
|
|
29
|
-
// Encoding not supported OR already encoded
|
|
30
24
|
if (response.isBase64Encoded || !preferredEncoding || !supportedContentEncodings.includes(preferredEncoding) || !response.body) {
|
|
31
25
|
return;
|
|
32
26
|
}
|
|
@@ -38,7 +32,6 @@ const defaults = {
|
|
|
38
32
|
contentEncoding = encoding;
|
|
39
33
|
break;
|
|
40
34
|
}
|
|
41
|
-
// Support streamifyResponse
|
|
42
35
|
if (response.body?._readableState) {
|
|
43
36
|
request.response.headers['Content-Encoding'] = contentEncoding;
|
|
44
37
|
request.response.body.pipe(contentEncodingStream);
|
|
@@ -49,9 +42,7 @@ const defaults = {
|
|
|
49
42
|
for await (const chunk of stream){
|
|
50
43
|
chunks.push(chunk);
|
|
51
44
|
}
|
|
52
|
-
// TODO update to btoa if faster
|
|
53
45
|
const body = Buffer.concat(chunks).toString('base64');
|
|
54
|
-
// Only apply encoding if it's smaller
|
|
55
46
|
if (body.length < response.body.length) {
|
|
56
47
|
response.headers['Content-Encoding'] = contentEncoding;
|
|
57
48
|
response.body = body;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/http-content-encoding",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "Http content encoding middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -63,10 +63,10 @@
|
|
|
63
63
|
"url": "https://github.com/sponsors/willfarrell"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@middy/util": "5.0
|
|
66
|
+
"@middy/util": "5.1.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@middy/core": "5.0
|
|
69
|
+
"@middy/core": "5.1.0"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "bbdaf5843914921804ba085dd58117273febe6b5"
|
|
72
72
|
}
|