php-ext-brotli icon indicating copy to clipboard operation
php-ext-brotli copied to clipboard

Do we have automatic header detection?

Open dinamic opened this issue 1 year ago • 2 comments

I'm working on a custom http client that'd support gzip as well as brotli. I'm parsing the http request headers and upon processing the headers I'm trying to apply a stream filter depending on the Content-Encoding header the server sent.

I noticed we've got automatic header detection with zlib.

See https://www.zlib.net/manual.html#Advanced definition of inflateInit2.

Add 32 to windowBits to enable zlib and gzip decoding with automatic header detection

In this PHP this can be used as:

stream_filter_append($stream, 'zlib.inflate', STREAM_FILTER_READ, ['window' => 15 + 32]);

Do we have means to do automatic header detection with Brotli? What a suggested approach would look like?

Thanks 🙏

dinamic avatar Jun 25 '24 10:06 dinamic

Unfortunately it doesn't seem to support detection of compressed files.

https://github.com/google/brotli/issues/867

kjdev avatar Jun 25 '24 22:06 kjdev

@kjdev https://github.com/google/brotli/issues/867 says that the comment option was added. Doesn't this mean the magic bytes were added and could be used to detect compressed files?

Turns out I wouldn't need the functionality, but it could be a nice feature to have.

dinamic avatar Jun 26 '24 07:06 dinamic