HMCL-dev/HMCL · error

Unsupported content encoding:

Error message

Unsupported content encoding: 

What it means

ContentEncoding.fromConnection inspects the HttpURLConnection's Content-Encoding header and maps known encodings (none/identity/gzip) to enum constants. Any other encoding value is not handled by HMCL, so an IOException is thrown rather than returning a stream the caller cannot decode.

Solutions

  1. Have the server/proxy serve gzip, identity, or no Content-Encoding for this client
  2. Remove 'br' or other exotic encodings from any configured Accept-Encoding request property
  3. If you control the request pipeline, decode the unsupported encoding before passing the connection to HMCL
  4. Patch/wrap fromConnection to support the needed encoding (e.g. Brotli via an InputStream wrapper)

Example fix

// before
connection.setRequestProperty("Accept-Encoding", "gzip, br");
// after
connection.setRequestProperty("Accept-Encoding", "gzip");
Defensive patterns

Strategy: try-catch

Validate before calling

String enc = connection.getContentEncoding();
boolean supported = enc == null || enc.isEmpty() || enc.equals("identity") || enc.equalsIgnoreCase("gzip");
if (!supported) throw new IOException("unsupported Content-Encoding: " + enc);

Try / catch

try (InputStream in = NetworkUtils...) { ... }
catch (IOException e) {
    if (e.getMessage().startsWith("Unsupported content encoding")) {
        // retry without compression or with a different endpoint
    } else throw e;
}

Prevention

When it happens

Trigger: Calling NetworkUtils download/GET helpers against a server that responds with Content-Encoding values like 'br' (Brotli), 'deflate', 'zstd', or a comma-combined list such as 'gzip, br'.

Common situations: Hitting CDNs or modern API endpoints that default to Brotli compression; misconfigured reverse proxies adding encodings; servers echoing an Accept-Encoding the client did not send.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of HMCL-dev/HMCL@24702dc5a0 (2026-09-10). Data as JSON: /api/errors/79847f3d65bde32d. Report an issue: GitHub.

Appendix: source

Thrown at HMCLCore/src/main/java/org/jackhuang/hmcl/util/io/ContentEncoding.java:52

        public InputStream wrap(InputStream inputStream) {
            return inputStream;
        }
    },
    GZIP {
        @Override
        public InputStream wrap(InputStream inputStream) throws IOException {
            return new GZIPInputStream(inputStream);
        }
    };

    public static @NotNull ContentEncoding fromConnection(URLConnection connection) throws IOException {
        String encoding = connection.getContentEncoding();
        if (encoding == null || encoding.isEmpty() || "identity".equals(encoding)) {
            return IDENTITY;
        } else if ("gzip".equalsIgnoreCase(encoding)) {
            return GZIP;
        } else {
            throw new IOException("Unsupported content encoding: " + encoding);
        }
    }

    public static @NotNull ContentEncoding fromHeaders(HttpHeaders headers) throws IOException {
        String encoding = headers.firstValue("content-encoding").orElse("");
        if (encoding.isEmpty() || "identity".equals(encoding)) {
            return IDENTITY;
        } else if ("gzip".equalsIgnoreCase(encoding)) {
            return GZIP;
        } else {
            throw new IOException("Unsupported content encoding: " + encoding);
        }
    }

    public abstract InputStream wrap(InputStream inputStream) throws IOException;
}

View on GitHub (pinned to 24702dc5a0)