@middy/http-content-encoding 5.5.1 → 6.0.0-beta.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 +22 -2
- package/package.json +8 -5
package/index.js
CHANGED
|
@@ -43,12 +43,21 @@ const httpContentEncodingMiddleware = (opts) => {
|
|
|
43
43
|
response
|
|
44
44
|
} = request
|
|
45
45
|
|
|
46
|
-
// Encoding not supported
|
|
46
|
+
// Encoding not supported, already encoded, or doesn't need to'
|
|
47
|
+
const eventCacheControl =
|
|
48
|
+
request.event.headers['cache-control'] ??
|
|
49
|
+
request.event.headers['Cache-Control']
|
|
50
|
+
if (eventCacheControl?.includes('no-transform')) {
|
|
51
|
+
addHeaderPart(response, 'Cache-Control', 'no-transform')
|
|
52
|
+
}
|
|
53
|
+
const responseCacheControl =
|
|
54
|
+
response.headers['Cache-Control'] ?? response.headers['cache-control']
|
|
47
55
|
if (
|
|
48
56
|
response.isBase64Encoded ||
|
|
49
57
|
!preferredEncoding ||
|
|
50
58
|
!supportedContentEncodings.includes(preferredEncoding) ||
|
|
51
|
-
!response.body
|
|
59
|
+
!response.body ||
|
|
60
|
+
responseCacheControl?.includes('no-transform')
|
|
52
61
|
) {
|
|
53
62
|
return
|
|
54
63
|
}
|
|
@@ -70,6 +79,7 @@ const httpContentEncodingMiddleware = (opts) => {
|
|
|
70
79
|
if (response.body?._readableState) {
|
|
71
80
|
request.response.headers['Content-Encoding'] = contentEncoding
|
|
72
81
|
request.response.body = request.response.body.pipe(contentEncodingStream)
|
|
82
|
+
addHeaderPart(response, 'Vary', 'Accept-Encoding')
|
|
73
83
|
return
|
|
74
84
|
}
|
|
75
85
|
|
|
@@ -87,6 +97,7 @@ const httpContentEncodingMiddleware = (opts) => {
|
|
|
87
97
|
response.headers['Content-Encoding'] = contentEncoding
|
|
88
98
|
response.body = body
|
|
89
99
|
response.isBase64Encoded = true
|
|
100
|
+
addHeaderPart(response, 'Vary', 'Accept-Encoding')
|
|
90
101
|
}
|
|
91
102
|
|
|
92
103
|
request.response = response
|
|
@@ -103,4 +114,13 @@ const httpContentEncodingMiddleware = (opts) => {
|
|
|
103
114
|
}
|
|
104
115
|
}
|
|
105
116
|
|
|
117
|
+
// header in offical name, lowercase varient handeled
|
|
118
|
+
const addHeaderPart = (response, header, value) => {
|
|
119
|
+
const headerLower = header.toLowerCase()
|
|
120
|
+
header = response.headers[headerLower] ? headerLower : header
|
|
121
|
+
response.headers[header] ??= ''
|
|
122
|
+
response.headers[header] &&= response.headers[header] + ', '
|
|
123
|
+
response.headers[header] += value
|
|
124
|
+
}
|
|
125
|
+
|
|
106
126
|
export default httpContentEncodingMiddleware
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/http-content-encoding",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-beta.0",
|
|
4
4
|
"description": "Http content encoding middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
7
|
-
"node": ">=
|
|
7
|
+
"node": ">=20"
|
|
8
8
|
},
|
|
9
9
|
"engineStrict": true,
|
|
10
10
|
"publishConfig": {
|
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
"import": {
|
|
17
17
|
"types": "./index.d.ts",
|
|
18
18
|
"default": "./index.js"
|
|
19
|
+
},
|
|
20
|
+
"require": {
|
|
21
|
+
"default": "./index.js"
|
|
19
22
|
}
|
|
20
23
|
}
|
|
21
24
|
},
|
|
@@ -63,11 +66,11 @@
|
|
|
63
66
|
"url": "https://github.com/sponsors/willfarrell"
|
|
64
67
|
},
|
|
65
68
|
"dependencies": {
|
|
66
|
-
"@middy/util": "
|
|
69
|
+
"@middy/util": "6.0.0-beta.0"
|
|
67
70
|
},
|
|
68
71
|
"devDependencies": {
|
|
69
|
-
"@datastream/core": "0.0.
|
|
70
|
-
"@middy/core": "
|
|
72
|
+
"@datastream/core": "0.0.40",
|
|
73
|
+
"@middy/core": "6.0.0-beta.0"
|
|
71
74
|
},
|
|
72
75
|
"gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431"
|
|
73
76
|
}
|