Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Content-Encoding, e.g. gzip'ed data #21

Closed
thekid opened this issue Feb 16, 2022 · 7 comments
Closed

Handle Content-Encoding, e.g. gzip'ed data #21

thekid opened this issue Feb 16, 2022 · 7 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@thekid
Copy link
Member

thekid commented Feb 16, 2022

Currently, the following is necessary in user code:

use io\streams\GzDecompressingInputStream;

$stream= match ($r->header('Content-Encoding')) {
  'gzip'  => new GzDecompressingInputStream($r->stream()),
  default => $r->stream(),
};

// Reading from $stream will yield original data
@thekid thekid added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Feb 16, 2022
@thekid
Copy link
Member Author

thekid commented Feb 16, 2022

We might encounter the following:

Content-Encoding: gzip
Content-Encoding: compress
Content-Encoding: deflate
Content-Encoding: br

// Multiple, in the order in which they were applied
Content-Encoding: deflate, gzip

See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding

@thekid
Copy link
Member Author

thekid commented Feb 17, 2022

Brotli would be added with xp-framework/core#307

@thekid
Copy link
Member Author

thekid commented Feb 19, 2022

...or alternatively with https://github.com/xp-forge/compression, wich has the following API:

@FileSystemCL<./src/main/php>
@FileSystemCL<./src/test/php>
package io.streams.compress {
  package io.streams.compress.unittest

  public class io.streams.compress.BrotliInputStream
  public class io.streams.compress.BrotliOutputStream
  public class io.streams.compress.Bzip2InputStream
  public class io.streams.compress.Bzip2OutputStream
  public class io.streams.compress.GzipInputStream
  public class io.streams.compress.GzipOutputStream
}

@thekid
Copy link
Member Author

thekid commented Feb 20, 2022

The HTTP deflate encoding is not supported by Apache and seems not to be widely supported by other servers:

The gzip encoding is the only one supported to ensure complete compatibility with old browser implementations. The deflate encoding is not supported, please check the zlib's documentation for a complete explanation.

Something very similar goes for compress:

The value name was taken from the UNIX compress program, which implemented this algorithm. Like the compress program, which has disappeared from most UNIX distributions, this content-encoding is not used by many browsers today, partly because of a patent issue (it expired in 2003).

We would be fine off if we support:

Content-Encoding: gzip
Content-Encoding: br

@thekid
Copy link
Member Author

thekid commented Feb 20, 2022

https://github.com/xp-forge/compression/releases/tag/v0.2.0 should not support this sufficiently

@thekid thekid mentioned this issue Feb 20, 2022
@thekid
Copy link
Member Author

thekid commented Feb 26, 2022

thekid added a commit that referenced this issue Feb 26, 2022
@thekid
Copy link
Member Author

thekid commented Feb 26, 2022

@thekid thekid closed this as completed Feb 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant