ContentEncoding

Enum
backed by string

Enum ContentEncoding.

Description

Represents common and experimental HTTP Content-Encoding header values. Content-Encoding defines the compression mechanism applied to the HTTP message body. Implementations using this enum MUST follow the semantics defined in RFC 7231, RFC 9110, and the relevant algorithm RFCs.

Each encoding describes a specific compression algorithm or an identity transformation. Servers and intermediaries using this enum SHOULD ensure that content negotiation is performed safely and consistently according to client capabilities, honoring q-values and alias mappings.

Table of Contents

Cases

Brotli

A format using the Brotli compression algorithm.

 = 'br'
Compress

A format using the Lempel-Ziv-Welch (LZW) algorithm.

 = 'compress'
Dcb

Experimental: A format using the Dictionary-Compressed Brotli algorithm.

 = 'dcb'
Dcz

Experimental: A format using the Dictionary-Compressed Zstandard algorithm.

 = 'dcz'
Deflate

A format using the zlib framing structure (RFC 1950) with the DEFLATE compression algorithm (RFC 1951).

 = 'deflate'
Gzip

A format using the Lempel-Ziv coding (LZ77) with a 32-bit CRC.

 = 'gzip'
Identity

Indicates the identity function (no compression).

 = 'identity'
Zstd

A format using the Zstandard compression algorithm.

 = 'zstd'

Methods

isSupported()

Determines whether a given encoding is acceptable according to an `Accept-Encoding` header value.

 : bool
getAliases()

Returns known alias names for a given encoding.

 : array<string|int, string>
Cases

Cases

Gzip

Case

A format using the Lempel-Ziv coding (LZ77) with a 32-bit CRC.

Description

The HTTP/1.1 standard states that servers supporting this encoding SHOULD also recognize "x-gzip" as an alias for compatibility. Implementations consuming this enum MUST treat both forms as equivalent during content negotiation.

Compress

Case

A format using the Lempel-Ziv-Welch (LZW) algorithm.

Description

Historically derived from the UNIX compress program. This encoding is largely obsolete in modern HTTP contexts and SHOULD NOT be used except for legacy interoperation.

Deflate

Case

A format using the zlib framing structure (RFC 1950) with the DEFLATE compression algorithm (RFC 1951).

Description

This encoding MUST NOT be confused with “raw deflate” streams.

Brotli

Case

A format using the Brotli compression algorithm.

Description

Defined in RFC 7932, Brotli provides modern general-purpose compression and SHOULD be preferred over older schemes such as gzip when client support is present.

Zstd

Case

A format using the Zstandard compression algorithm.

Description

Defined in RFC 8878, Zstandard (“zstd”) offers high compression ratios and fast decompression. Implementations MAY use dictionary compression where supported by the protocol extension.

Identity

Case

Indicates the identity function (no compression).

Description

The identity encoding MUST be considered acceptable if the client omits an Accept-Encoding header. It MUST NOT apply any compression transformation to the content.

Dcb

Case

Experimental: A format using the Dictionary-Compressed Brotli algorithm.

Description

See the Compression Dictionary Transport specification. This encoding is experimental and MAY NOT be supported by all clients.

Dcz

Case

Experimental: A format using the Dictionary-Compressed Zstandard algorithm.

Description

See the Compression Dictionary Transport specification. This encoding is experimental and MAY NOT be supported by all clients.

Methods

isSupported()

Public Static

Determines whether a given encoding is acceptable according to an `Accept-Encoding` header value.

public static isSupported( self  $encoding, string  $acceptEncodingHeader) : bool

Description

This method MUST correctly apply HTTP content negotiation rules:

  • Parse q-values, which MUST determine the client's preference level.
  • Interpret “q=0” as explicit rejection.
  • Support wildcards (“*”) as fallback.
  • Recognize “x-gzip” as an alias for the gzip encoding. If an encoding is not explicitly listed and no wildcard is present, the encoding SHOULD be considered acceptable unless the header exclusively lists explicit rejections.
Parameters
$encoding : self

Description

the encoding to evaluate

$acceptEncodingHeader : string

Description

the raw Accept-Encoding header value

Return values
bool

Description

true if the encoding is acceptable according to negotiation rules

getAliases()

Private Static

Returns known alias names for a given encoding.

private static getAliases( self  $encoding) : array<string|int, string>

Description

Implementations MUST treat aliases as equivalent when performing content negotiation. Currently only gzip uses an alias (“x-gzip”), but future extensions MAY introduce additional aliases.

Parameters
$encoding : self

Description

the encoding whose aliases will be returned

Return values
array<string|int, string>

Description

a list of lowercase alias identifiers