@naturalcycles/backend-lib 9.46.0 → 9.46.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.
@@ -157,8 +157,11 @@ export function compressionMiddleware(options) {
157
157
  return;
158
158
  }
159
159
  // compression method
160
+ // Get all client-accepted encodings, then pick the first one from our preferred order
160
161
  const negotiator = new Negotiator(req);
161
- let method = negotiator.encoding(SUPPORTED_ENCODING, PREFERRED_ENCODING);
162
+ const clientEncodings = negotiator.encodings(SUPPORTED_ENCODING);
163
+ // Prefer server's order, but fall back to client's first choice if no preferred match
164
+ let method = PREFERRED_ENCODING.find(enc => clientEncodings.includes(enc)) || clientEncodings[0];
162
165
  // if no method is found, use the default encoding
163
166
  if (!req.headers['accept-encoding'] && encodingSupported.has(enforceEncoding)) {
164
167
  method = enforceEncoding;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
3
  "type": "module",
4
- "version": "9.46.0",
4
+ "version": "9.46.1",
5
5
  "peerDependencies": {
6
6
  "@sentry/node": "^10"
7
7
  },
@@ -239,8 +239,12 @@ export function compressionMiddleware(options?: CompressionOptions): BackendRequ
239
239
  }
240
240
 
241
241
  // compression method
242
+ // Get all client-accepted encodings, then pick the first one from our preferred order
242
243
  const negotiator = new Negotiator(req)
243
- let method: string | undefined = negotiator.encoding(SUPPORTED_ENCODING, PREFERRED_ENCODING)
244
+ const clientEncodings = negotiator.encodings(SUPPORTED_ENCODING) as string[]
245
+ // Prefer server's order, but fall back to client's first choice if no preferred match
246
+ let method: string | undefined =
247
+ PREFERRED_ENCODING.find(enc => clientEncodings.includes(enc)) || clientEncodings[0]
244
248
 
245
249
  // if no method is found, use the default encoding
246
250
  if (!req.headers['accept-encoding'] && encodingSupported.has(enforceEncoding)) {