@adobe/spacecat-shared-http-utils 1.17.9 → 1.18.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [@adobe/spacecat-shared-http-utils-v1.18.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-http-utils-v1.18.0...@adobe/spacecat-shared-http-utils-v1.18.1) (2025-11-15)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **deps:** update external fixes ([#1131](https://github.com/adobe/spacecat-shared/issues/1131)) ([d4a3f4a](https://github.com/adobe/spacecat-shared/commit/d4a3f4a653e59e9bdde7926ea8f1a2f9b68739ff))
7
+
8
+ # [@adobe/spacecat-shared-http-utils-v1.18.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-http-utils-v1.17.9...@adobe/spacecat-shared-http-utils-v1.18.0) (2025-11-06)
9
+
10
+
11
+ ### Features
12
+
13
+ * allow brotli compression for json responses ([#1095](https://github.com/adobe/spacecat-shared/issues/1095)) ([b81f349](https://github.com/adobe/spacecat-shared/commit/b81f3497d7a64dd1b2a888f98971f7913e3ff1db))
14
+
1
15
  # [@adobe/spacecat-shared-http-utils-v1.17.9](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-http-utils-v1.17.8...@adobe/spacecat-shared-http-utils-v1.17.9) (2025-10-28)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-http-utils",
3
- "version": "1.17.9",
3
+ "version": "1.18.1",
4
4
  "description": "Shared modules of the Spacecat Services - HTTP Utils",
5
5
  "type": "module",
6
6
  "engines": {
@@ -37,11 +37,11 @@
37
37
  "@adobe/fetch": "4.2.3",
38
38
  "@adobe/spacecat-shared-data-access": "2.45.0",
39
39
  "@adobe/spacecat-shared-utils": "1.66.0",
40
- "jose": "6.1.0"
40
+ "jose": "6.1.1"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@adobe/helix-shared-wrap": "2.0.2",
44
- "chai": "6.2.0",
44
+ "chai": "6.2.1",
45
45
  "chai-as-promised": "8.0.2",
46
46
  "sinon": "21.0.0"
47
47
  }
package/src/index.js CHANGED
@@ -11,7 +11,7 @@
11
11
  */
12
12
 
13
13
  import { Response } from '@adobe/fetch';
14
- import { gzipSync } from 'zlib';
14
+ import { brotliCompressSync, gzipSync, constants as zlibConstants } from 'zlib';
15
15
 
16
16
  import LegacyApiKeyHandler from './auth/handlers/legacy-api-key.js';
17
17
  import AdobeImsHandler from './auth/handlers/ims.js';
@@ -64,6 +64,7 @@ export function createResponse(body, status = 200, headers = {}) {
64
64
  const contentType = getHeader(headers, HEADER_CONTENT_TYPE);
65
65
  const contentEncoding = getHeader(headers, HEADER_CONTENT_ENCODING);
66
66
  const wantsGzip = contentEncoding?.toLowerCase() === 'gzip';
67
+ const wantsBrotli = contentEncoding?.toLowerCase() === 'br';
67
68
 
68
69
  // default to application/json if content-type not set
69
70
  if (!contentType) {
@@ -72,10 +73,22 @@ export function createResponse(body, status = 200, headers = {}) {
72
73
 
73
74
  const finalContentType = getHeader(headers, HEADER_CONTENT_TYPE);
74
75
 
75
- // if content-type is JSON, serialize and optionally gzip
76
+ // if content-type is JSON, serialize and optionally compress
76
77
  if (finalContentType?.toLowerCase().includes(CONTENT_TYPE_JSON)) {
77
78
  const jsonBody = body === '' ? '' : JSON.stringify(body);
78
- responseBody = wantsGzip ? gzipSync(Buffer.from(jsonBody)) : jsonBody;
79
+
80
+ if (wantsGzip) {
81
+ responseBody = gzipSync(Buffer.from(jsonBody));
82
+ } else if (wantsBrotli) {
83
+ responseBody = brotliCompressSync(Buffer.from(jsonBody), {
84
+ params: {
85
+ // the default quality is too complex for the lambda and can lead to 503s
86
+ [zlibConstants.BROTLI_PARAM_QUALITY]: 4,
87
+ },
88
+ });
89
+ } else {
90
+ responseBody = jsonBody;
91
+ }
79
92
  }
80
93
 
81
94
  return new Response(responseBody, {