mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
LibHTTP: Be more tolerant about bad chunked encoding trailers
Some servers (*glares at cloudflare*) like to send two last chunks, which is strictly against the spec. Let's be more tolerant of this behaviour.
This commit is contained in:
parent
49c5acaa3d
commit
ec0315883b
Notes:
sideshowbarker
2024-07-19 04:36:38 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/ec0315883be Pull-request: https://github.com/SerenityOS/serenity/pull/2881
2 changed files with 19 additions and 0 deletions
|
@ -51,6 +51,7 @@ public:
|
|||
virtual void shutdown() override;
|
||||
|
||||
protected:
|
||||
virtual bool should_fail_on_empty_payload() const override { return false; }
|
||||
virtual void register_on_ready_to_read(Function<void()>) override;
|
||||
virtual void register_on_ready_to_write(Function<void()>) override;
|
||||
virtual bool can_read_line() const override;
|
||||
|
|
|
@ -122,6 +122,12 @@ void Job::on_socket_connected()
|
|||
return;
|
||||
auto line = read_line(PAGE_SIZE);
|
||||
if (line.is_null()) {
|
||||
if (m_state == State::AfterChunkedEncodingTrailer) {
|
||||
// Some servers like to send two ending chunks
|
||||
// use this fact as an excuse to ignore anything after the last chunk
|
||||
// that is not a valid trailing header.
|
||||
return finish_up();
|
||||
}
|
||||
fprintf(stderr, "Job: Expected HTTP header\n");
|
||||
return did_fail(Core::NetworkJob::Error::ProtocolFailed);
|
||||
}
|
||||
|
@ -136,11 +142,23 @@ void Job::on_socket_connected()
|
|||
}
|
||||
auto parts = chomped_line.split(':');
|
||||
if (parts.is_empty()) {
|
||||
if (m_state == State::AfterChunkedEncodingTrailer) {
|
||||
// Some servers like to send two ending chunks
|
||||
// use this fact as an excuse to ignore anything after the last chunk
|
||||
// that is not a valid trailing header.
|
||||
return finish_up();
|
||||
}
|
||||
fprintf(stderr, "Job: Expected HTTP header with key/value\n");
|
||||
return deferred_invoke([this](auto&) { did_fail(Core::NetworkJob::Error::ProtocolFailed); });
|
||||
}
|
||||
auto name = parts[0];
|
||||
if (chomped_line.length() < name.length() + 2) {
|
||||
if (m_state == State::AfterChunkedEncodingTrailer) {
|
||||
// Some servers like to send two ending chunks
|
||||
// use this fact as an excuse to ignore anything after the last chunk
|
||||
// that is not a valid trailing header.
|
||||
return finish_up();
|
||||
}
|
||||
fprintf(stderr, "Job: Malformed HTTP header: '%s' (%zu)\n", chomped_line.characters(), chomped_line.length());
|
||||
return deferred_invoke([this](auto&) { did_fail(Core::NetworkJob::Error::ProtocolFailed); });
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue