LibHTTP+LibTLS: Better HTTPS Socket EOF detection
When the server doesn't signal the Content-Length or use a chunked mode, it may just terminate the connection after sending the data. The TLS sockets would then get stuck in a state with no data to read and not reach the disconnected state, making some requests hang. We know double check the EOF status of HTTP jobs after reading the payload to resolve requests properly and also mark the TLS sockets as EOF after processing all the data and the underlying TCP socket reaches EOF. Fixes #12866.
This commit is contained in:
parent
29f91ceeed
commit
e165ae5b60
Notes:
sideshowbarker
2024-07-17 17:04:22 +09:00
Author: https://github.com/Orphis 🔰 Commit: https://github.com/SerenityOS/serenity/commit/e165ae5b60 Pull-request: https://github.com/SerenityOS/serenity/pull/13146 Issue: https://github.com/SerenityOS/serenity/issues/12866 Reviewed-by: https://github.com/alimpfard ✅
2 changed files with 9 additions and 1 deletions
|
@ -504,6 +504,14 @@ void Job::on_socket_connected()
|
|||
break;
|
||||
}
|
||||
|
||||
// Check after reading all the buffered data if we have reached the end of stream
|
||||
// for cases where the server didn't send a content length, chunked encoding but is
|
||||
// directly closing the connection.
|
||||
if (!m_content_length.has_value() && !m_current_chunk_remaining_size.has_value() && m_socket->is_eof()) {
|
||||
finish_up();
|
||||
break;
|
||||
}
|
||||
|
||||
if (m_current_chunk_remaining_size.has_value()) {
|
||||
auto size = m_current_chunk_remaining_size.value() - payload.size();
|
||||
|
||||
|
|
|
@ -365,7 +365,7 @@ public:
|
|||
/// bytes written into the stream, or an errno in the case of failure.
|
||||
virtual ErrorOr<size_t> write(ReadonlyBytes) override;
|
||||
|
||||
virtual bool is_eof() const override { return m_context.connection_finished && m_context.application_buffer.is_empty(); }
|
||||
virtual bool is_eof() const override { return m_context.application_buffer.is_empty() && (m_context.connection_finished || underlying_stream().is_eof()); }
|
||||
|
||||
virtual bool is_open() const override { return is_established(); }
|
||||
virtual void close() override;
|
||||
|
|
Loading…
Add table
Reference in a new issue