mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:17:45 +00:00
LibCompress: Port ZlibDecompressor
to AK::Stream
This commit is contained in:
parent
90780d9ade
commit
8a853278d0
7 changed files with 96 additions and 68 deletions
|
@ -51,13 +51,17 @@ static ErrorOr<ByteBuffer> handle_content_encoding(ByteBuffer const& buf, Deprec
|
|||
|
||||
// Even though the content encoding is "deflate", it's actually deflate with the zlib wrapper.
|
||||
// https://tools.ietf.org/html/rfc7230#section-4.2.2
|
||||
auto uncompressed = Compress::ZlibDecompressor::decompress_all(buf);
|
||||
if (!uncompressed.has_value()) {
|
||||
auto memory_stream = make<FixedMemoryStream>(buf);
|
||||
auto zlib_decompressor = Compress::ZlibDecompressor::create(move(memory_stream));
|
||||
Optional<ByteBuffer> uncompressed;
|
||||
if (zlib_decompressor.is_error()) {
|
||||
// From the RFC:
|
||||
// "Note: Some non-conformant implementations send the "deflate"
|
||||
// compressed data without the zlib wrapper."
|
||||
dbgln_if(JOB_DEBUG, "Job::handle_content_encoding: ZlibDecompressor::decompress_all() failed. Trying DeflateDecompressor::decompress_all()");
|
||||
uncompressed = TRY(Compress::DeflateDecompressor::decompress_all(buf));
|
||||
} else {
|
||||
uncompressed = TRY(zlib_decompressor.value()->read_until_eof());
|
||||
}
|
||||
|
||||
if constexpr (JOB_DEBUG) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue