Skip to content

Truly independent web browser

RequestServer: Include the HTTP version in response notifications

Andreas Klingcae49bf2daff
diff --git a/Libraries/LibRequests/Request.cpp b/Libraries/LibRequests/Request.cpp
index 9178d280fff..7ee16b363e4 100644
--- a/Libraries/LibRequests/Request.cpp
+++ b/Libraries/LibRequests/Request.cpp
@@ -334,8 +334,9 @@ void Request::did_finish(Badge<RequestClient>, u64 total_size, RequestTimingInfo
on_finish(total_size, timing_info, effective_network_error);
}
-void Request::did_receive_headers(Badge<RequestClient>, NonnullRefPtr<HTTP::HeaderList> response_headers, Optional<u32> response_code, Optional<String> const& reason_phrase, Optional<Core::ImmutableBytes> javascript_bytecode, Optional<u64> javascript_bytecode_cache_vary_key, CacheState cache_state)
+void Request::did_receive_headers(Badge<RequestClient>, NonnullRefPtr<HTTP::HeaderList> response_headers, Optional<u32> response_code, Optional<String> const& reason_phrase, Optional<Core::ImmutableBytes> javascript_bytecode, Optional<u64> javascript_bytecode_cache_vary_key, CacheState cache_state, ByteString http_version)
{
+ m_http_version = move(http_version);
if (on_headers_received)
on_headers_received(move(response_headers), response_code, reason_phrase, move(javascript_bytecode), javascript_bytecode_cache_vary_key, cache_state);
}
diff --git a/Libraries/LibRequests/Request.h b/Libraries/LibRequests/Request.h
index 18a059165e9..478ea3c368e 100644
--- a/Libraries/LibRequests/Request.h
+++ b/Libraries/LibRequests/Request.h
@@ -93,6 +93,7 @@ public:
u64 id() const { return m_request_id; }
int request_server_client_id() const;
int fd() const { return m_fd; }
+ ByteString const& http_version() const { return m_http_version; }
bool stop();
void set_body_delivery_paused(bool);
void resume_body_delivery();
@@ -128,7 +129,7 @@ public:
Function<void()> on_teardown;
void did_finish(Badge<RequestClient>, u64 total_size, RequestTimingInfo const& timing_info, Optional<NetworkError> const& network_error);
- void did_receive_headers(Badge<RequestClient>, NonnullRefPtr<HTTP::HeaderList> response_headers, Optional<u32> response_code, Optional<String> const& reason_phrase, Optional<Core::ImmutableBytes> javascript_bytecode, Optional<u64> javascript_bytecode_cache_vary_key, CacheState cache_state);
+ void did_receive_headers(Badge<RequestClient>, NonnullRefPtr<HTTP::HeaderList> response_headers, Optional<u32> response_code, Optional<String> const& reason_phrase, Optional<Core::ImmutableBytes> javascript_bytecode, Optional<u64> javascript_bytecode_cache_vary_key, CacheState cache_state, ByteString http_version);
void did_transfer(Badge<RequestClient>);
RefPtr<Core::Notifier>& write_notifier(Badge<RequestClient>) { return m_write_notifier; }
@@ -208,6 +209,7 @@ private:
Optional<NetworkError> m_body_delivery_error;
bool m_body_delivery_paused { false };
bool m_finished { false };
+ ByteString m_http_version;
};
}
diff --git a/Libraries/LibRequests/RequestClient.cpp b/Libraries/LibRequests/RequestClient.cpp
index d117eb55dbd..338247d43d6 100644
--- a/Libraries/LibRequests/RequestClient.cpp
+++ b/Libraries/LibRequests/RequestClient.cpp
@@ -243,7 +243,7 @@ void RequestClient::request_finished(u64 request_id, u64 total_size, RequestTimi
m_requests.remove(request_id);
}
-void RequestClient::headers_became_available(u64 request_id, Vector<HTTP::Header> response_headers, Optional<u32> status_code, Optional<String> reason_phrase, Optional<IPC::File> javascript_bytecode_file, u64 javascript_bytecode_size, Optional<u64> javascript_bytecode_cache_vary_key, CacheState cache_state)
+void RequestClient::headers_became_available(u64 request_id, Vector<HTTP::Header> response_headers, Optional<u32> status_code, Optional<String> reason_phrase, Optional<IPC::File> javascript_bytecode_file, u64 javascript_bytecode_size, Optional<u64> javascript_bytecode_cache_vary_key, CacheState cache_state, ByteString http_version)
{
Optional<Core::ImmutableBytes> javascript_bytecode;
if (javascript_bytecode_file.has_value())
@@ -251,7 +251,7 @@ void RequestClient::headers_became_available(u64 request_id, Vector<HTTP::Header
RefPtr<Request> request = m_requests.get(request_id).value_or(nullptr);
if (request)
- request->did_receive_headers({}, HTTP::HeaderList::create(move(response_headers)), status_code, reason_phrase, move(javascript_bytecode), javascript_bytecode_cache_vary_key, cache_state);
+ request->did_receive_headers({}, HTTP::HeaderList::create(move(response_headers)), status_code, reason_phrase, move(javascript_bytecode), javascript_bytecode_cache_vary_key, cache_state, move(http_version));
else
warnln("Received headers for non-existent request {}", request_id);
}
diff --git a/Libraries/LibRequests/RequestClient.h b/Libraries/LibRequests/RequestClient.h
index 3946c33fa58..3c8217040df 100644
--- a/Libraries/LibRequests/RequestClient.h
+++ b/Libraries/LibRequests/RequestClient.h
@@ -81,7 +81,7 @@ private:
virtual void request_body_file_available(u64 request_id, IPC::File, u64 offset, u64 size) override;
virtual void request_cached_body_file_available(u64 request_id, IPC::File, u64 offset, u64 size) override;
virtual void request_finished(u64 request_id, u64, RequestTimingInfo, Optional<NetworkError>) override;
- virtual void headers_became_available(u64 request_id, Vector<HTTP::Header>, Optional<u32>, Optional<String>, Optional<IPC::File>, u64 javascript_bytecode_size, Optional<u64>, CacheState) override;
+ virtual void headers_became_available(u64 request_id, Vector<HTTP::Header>, Optional<u32>, Optional<String>, Optional<IPC::File>, u64 javascript_bytecode_size, Optional<u64>, CacheState, ByteString http_version) override;
virtual void request_transferred(u64 request_id) override;
virtual void websocket_connected(u64 websocket_id) override;
diff --git a/Services/RequestServer/Request.cpp b/Services/RequestServer/Request.cpp
index b8053954b52..2ddb8ab9eba 100644
--- a/Services/RequestServer/Request.cpp
+++ b/Services/RequestServer/Request.cpp
@@ -1969,8 +1969,11 @@ size_t Request::on_header_received(void* buffer, size_t size, size_t nmemb, void
// We need to extract the HTTP reason phrase since it can be a custom value. Fetching infrastructure needs this
// value for setting the status message.
auto space_index = header_line.find(' ');
- if (space_index.has_value())
+ if (space_index.has_value()) {
+ // NB: Observers need the HTTP version before the response body finishes.
+ request.m_http_version = ByteString(header_line.substring_view(0, *space_index)).to_lowercase();
space_index = header_line.find(' ', *space_index + 1);
+ }
if (space_index.has_value()) {
if (auto reason_phrase = HTTP::normalize_header_value(header_line.substring_view(*space_index + 1)); !reason_phrase.is_empty()) {
@@ -2258,7 +2261,7 @@ void Request::send_headers_to_client(Optional<IPC::File> javascript_bytecode, u6
auto cache_state = Requests::CacheState::NotCached;
if (m_cache_status == CacheStatus::ReadFromCache)
cache_state = m_cache_entry_was_revalidated ? Requests::CacheState::Validated : Requests::CacheState::Local;
- m_client->async_headers_became_available(m_request_id, m_response_headers->headers(), m_status_code, m_reason_phrase, move(javascript_bytecode), javascript_bytecode_size, javascript_bytecode_cache_vary_key, cache_state);
+ m_client->async_headers_became_available(m_request_id, m_response_headers->headers(), m_status_code, m_reason_phrase, move(javascript_bytecode), javascript_bytecode_size, javascript_bytecode_cache_vary_key, cache_state, m_http_version);
}
ErrorOr<void> Request::write_queued_bytes_without_blocking()
diff --git a/Services/RequestServer/Request.h b/Services/RequestServer/Request.h
index 63fd505c1f4..b6bedba0d36 100644
--- a/Services/RequestServer/Request.h
+++ b/Services/RequestServer/Request.h
@@ -351,6 +351,7 @@ private:
Optional<u32> m_status_code;
Optional<String> m_reason_phrase;
+ ByteString m_http_version;
NonnullRefPtr<HTTP::HeaderList> m_response_headers;
// Cache the first spelling of each header name to avoid repeated HeaderList searches.
diff --git a/Services/RequestServer/RequestClient.ipc b/Services/RequestServer/RequestClient.ipc
index 59231ebbeaa..088004dcd2e 100644
--- a/Services/RequestServer/RequestClient.ipc
+++ b/Services/RequestServer/RequestClient.ipc
@@ -13,7 +13,7 @@ endpoint RequestClient
request_body_file_available(u64 request_id, IPC::File fd, u64 offset, u64 size) =|
request_cached_body_file_available(u64 request_id, IPC::File fd, u64 offset, u64 size) =|
request_finished(u64 request_id, u64 total_size, Requests::RequestTimingInfo timing_info, Optional<Requests::NetworkError> network_error) =|
- headers_became_available(u64 request_id, Vector<HTTP::Header> response_headers, Optional<u32> status_code, Optional<String> reason_phrase, Optional<IPC::File> javascript_bytecode, u64 javascript_bytecode_size, Optional<u64> javascript_bytecode_cache_vary_key, Requests::CacheState cache_state) =|
+ headers_became_available(u64 request_id, Vector<HTTP::Header> response_headers, Optional<u32> status_code, Optional<String> reason_phrase, Optional<IPC::File> javascript_bytecode, u64 javascript_bytecode_size, Optional<u64> javascript_bytecode_cache_vary_key, Requests::CacheState cache_state, ByteString http_version) =|
request_transferred(u64 request_id) =|
// Websocket API