diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-10-04 14:22:48 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-04 13:06:03 +0200 |
commit | 3564e4eff1790b7ea3db74c300bd8b9fdd0af020 (patch) | |
tree | f2312bb753fec8b8a4e87692c1d16df33bd40d50 /Userland/Libraries/LibHTTP | |
parent | 6e58b71c83800e9f387906da32d0f6998fac43f4 (diff) | |
download | serenity-3564e4eff1790b7ea3db74c300bd8b9fdd0af020.zip |
LibHTTP: Consider a job failed if its body fails decompression
Our previous behaviour of treating the original invalid compressed body
as the decompressed response is quite silly, if the headers and response
doesn't match up, the job has failed.
Diffstat (limited to 'Userland/Libraries/LibHTTP')
-rw-r--r-- | Userland/Libraries/LibHTTP/Job.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/Userland/Libraries/LibHTTP/Job.cpp b/Userland/Libraries/LibHTTP/Job.cpp index 8141a3e869..c60ebb8651 100644 --- a/Userland/Libraries/LibHTTP/Job.cpp +++ b/Userland/Libraries/LibHTTP/Job.cpp @@ -16,7 +16,7 @@ namespace HTTP { -static ByteBuffer handle_content_encoding(const ByteBuffer& buf, const String& content_encoding) +static Optional<ByteBuffer> handle_content_encoding(const ByteBuffer& buf, const String& content_encoding) { dbgln_if(JOB_DEBUG, "Job::handle_content_encoding: buf has content_encoding={}", content_encoding); @@ -29,8 +29,8 @@ static ByteBuffer handle_content_encoding(const ByteBuffer& buf, const String& c auto uncompressed = Compress::GzipDecompressor::decompress_all(buf); if (!uncompressed.has_value()) { - dbgln("Job::handle_content_encoding: Gzip::decompress() failed. Returning original buffer."); - return buf; + dbgln("Job::handle_content_encoding: Gzip::decompress() failed."); + return {}; } if constexpr (JOB_DEBUG) { @@ -54,8 +54,8 @@ static ByteBuffer handle_content_encoding(const ByteBuffer& buf, const String& c uncompressed = Compress::DeflateDecompressor::decompress_all(buf); if (!uncompressed.has_value()) { - dbgln("Job::handle_content_encoding: DeflateDecompressor::decompress_all() failed, returning original buffer."); - return buf; + dbgln("Job::handle_content_encoding: DeflateDecompressor::decompress_all() failed."); + return {}; } } @@ -389,7 +389,10 @@ void Job::finish_up() // FIXME: LibCompress exposes a streaming interface, so this can be resolved auto content_encoding = m_headers.get("Content-Encoding"); if (content_encoding.has_value()) { - flattened_buffer = handle_content_encoding(flattened_buffer, content_encoding.value()); + if (auto result = handle_content_encoding(flattened_buffer, content_encoding.value()); result.has_value()) + flattened_buffer = result.release_value(); + else + return did_fail(Core::NetworkJob::Error::TransmissionFailed); } m_buffered_size = flattened_buffer.size(); |