@middy/http-content-encoding 6.0.0-alpha.0 → 6.0.0-beta.1

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.
Files changed (2) hide show
  1. package/index.js +22 -2
  2. package/package.json +4 -4
package/index.js CHANGED
@@ -43,12 +43,21 @@ const httpContentEncodingMiddleware = (opts) => {
43
43
  response
44
44
  } = request
45
45
 
46
- // Encoding not supported OR already encoded
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/http-content-encoding",
3
- "version": "6.0.0-alpha.0",
3
+ "version": "6.0.0-beta.1",
4
4
  "description": "Http content encoding middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -66,11 +66,11 @@
66
66
  "url": "https://github.com/sponsors/willfarrell"
67
67
  },
68
68
  "dependencies": {
69
- "@middy/util": "6.0.0-alpha.0"
69
+ "@middy/util": "6.0.0-beta.1"
70
70
  },
71
71
  "devDependencies": {
72
- "@datastream/core": "0.0.38",
73
- "@middy/core": "6.0.0-alpha.0"
72
+ "@datastream/core": "0.0.40",
73
+ "@middy/core": "6.0.0-beta.1"
74
74
  },
75
75
  "gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431"
76
76
  }