Skip to content

Accept-Encoding: * wildcard is ignored during compression negotiation #193

Closed

Description

@VikramAditya33

Per RFC 7231, Accept-Encoding: * means the client accepts any encoding. Currently, CompressionHandler.parseAcceptEncoding treats * as an unknown token with priority 0, so responses to Accept-Encoding: * requests are sent uncompressed.

Reproduction

const handler = new CompressionHandler({ brotli: true });
// Client says "I accept any encoding"
setupMock('*', 'text/plain');

const stream = handler.createCompressionStream(req, res, largeBody);
// Expected: brotli compression stream
// Actual: null (no compression applied)

Root Cause

parseAcceptEncoding parses * literally into the encodings list, but createCompressionStream's switch statement only matches br, gzip, and deflate. The * token falls through all cases.

Proposed Fix

Expand * into supported encodings that are not explicitly listed or explicitly rejected (q=0):

// In parseAcceptEncoding:
const rejected = new Set<string>();
let wildcardQuality: number | null = null;

// ...during parsing:
if (encoding.trim() === '*') {
  wildcardQuality = quality;
  continue;
}

if (quality > 0) {
  encodings.push({ ... });
} else {
  rejected.add(encoding.trim().toLowerCase());
}

// ...after parsing:
if (wildcardQuality !== null && wildcardQuality > 0) {
  for (const supported of ['br', 'gzip', 'deflate']) {
    if (!encodings.some((e) => e.encoding === supported) && !rejected.has(supported)) {
      encodings.push({
        encoding: supported,
        quality: wildcardQuality,
        position: Number.MAX_SAFE_INTEGER,
      });
    }
  }
}

Edge Case Handled

Accept-Encoding: gzip;q=0, * → wildcard expands to br and deflate only; gzip remains excluded because it was explicitly rejected.

Activity

  1. added this to the v2.1.0 milestone on May 23, 2026
  2. added
    bug
    good first issue
    on May 23, 2026
  3. wahajahmed010 commented on May 28, 2026

    @wahajahmed010
    Contributor

    Hi! I'd like to work on this issue. Could you please assign it to me? I have a PR open (#196) that addresses this.

  4. added a commit that references this issue on May 28, 2026
    c266888
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

buggood first issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions