RequestServer: Move Request::Type enum to its own file

This will make it a bit easier to transfer over IPC.
This commit is contained in:
Timothy Flynn 2026-04-13 16:43:32 -04:00 committed by Tim Flynn
parent 649b7fa32d
commit 09e8299721
4 changed files with 42 additions and 28 deletions

View file

@ -79,7 +79,7 @@ void ConnectionFromClient::request_complete(Badge<Request>, Request const& reque
{
Core::deferred_invoke([weak_self = make_weak_ptr<ConnectionFromClient>(), request_id = request.request_id(), type = request.type()] {
if (auto self = weak_self.strong_ref()) {
if (type == Request::Type::BackgroundRevalidation)
if (type == RequestType::BackgroundRevalidation)
self->m_active_revalidation_requests.remove(request_id);
else
self->m_active_requests.remove(request_id);

View file

@ -40,7 +40,7 @@ NonnullOwnPtr<Request> Request::fetch(
ByteString alt_svc_cache_path,
Core::ProxyData proxy_data)
{
auto request = adopt_own(*new Request { request_id, Type::Fetch, disk_cache, cache_mode, client, curl_multi, resolver, move(url), move(method), move(request_headers), move(request_body), include_credentials, move(alt_svc_cache_path), proxy_data });
auto request = adopt_own(*new Request { request_id, RequestType::Fetch, disk_cache, cache_mode, client, curl_multi, resolver, move(url), move(method), move(request_headers), move(request_body), include_credentials, move(alt_svc_cache_path), proxy_data });
request->process();
return request;
@ -82,7 +82,7 @@ NonnullOwnPtr<Request> Request::revalidate(
ByteString alt_svc_cache_path,
Core::ProxyData proxy_data)
{
auto request = adopt_own(*new Request { request_id, Type::BackgroundRevalidation, disk_cache, HTTP::CacheMode::Default, client, curl_multi, resolver, move(url), move(method), move(request_headers), move(request_body), include_credentials, move(alt_svc_cache_path), proxy_data });
auto request = adopt_own(*new Request { request_id, RequestType::BackgroundRevalidation, disk_cache, HTTP::CacheMode::Default, client, curl_multi, resolver, move(url), move(method), move(request_headers), move(request_body), include_credentials, move(alt_svc_cache_path), proxy_data });
request->process();
return request;
@ -90,7 +90,7 @@ NonnullOwnPtr<Request> Request::revalidate(
Request::Request(
u64 request_id,
Type type,
RequestType type,
Optional<HTTP::DiskCache&> disk_cache,
HTTP::CacheMode cache_mode,
ConnectionFromClient& client,
@ -128,7 +128,7 @@ Request::Request(
Resolver& resolver,
URL::URL url)
: m_request_id(request_id)
, m_type(Type::Connect)
, m_type(RequestType::Connect)
, m_client(client)
, m_curl_multi_handle(curl_multi)
, m_resolver(resolver)
@ -182,11 +182,11 @@ void Request::notify_fetch_complete(Badge<ConnectionFromClient>, int result_code
{
if (is_revalidation_request()) {
if (acquire_status_code() == 304) {
if (m_type == Type::BackgroundRevalidation && m_disk_cache->mode() == HTTP::DiskCache::Mode::Testing)
if (m_type == RequestType::BackgroundRevalidation && m_disk_cache->mode() == HTTP::DiskCache::Mode::Testing)
m_response_headers->set({ HTTP::TEST_CACHE_REVALIDATION_STATUS_HEADER, "fresh"sv });
m_cache_entry_reader->revalidation_succeeded(m_response_headers);
transition_to_state(m_type == Type::Fetch ? State::ReadCache : State::Complete);
transition_to_state(m_type == RequestType::Fetch ? State::ReadCache : State::Complete);
return;
}
@ -261,7 +261,7 @@ void Request::handle_initial_state()
if (m_cache_mode == HTTP::CacheMode::NoStore) {
m_cache_status = HTTP::CacheRequest::CacheStatus::NotCached;
} else if (m_disk_cache.has_value()) {
auto open_mode = m_type == Type::BackgroundRevalidation
auto open_mode = m_type == RequestType::BackgroundRevalidation
? HTTP::DiskCache::OpenMode::Revalidate
: HTTP::DiskCache::OpenMode::Read;
@ -278,7 +278,7 @@ void Request::handle_initial_state()
transition_to_state(State::DNSLookup);
else
transition_to_state(State::ReadCache);
} else if (m_type == Type::BackgroundRevalidation) {
} else if (m_type == RequestType::BackgroundRevalidation) {
// If we were not able to open a cache entry reader for revalidation requests, there's no point
// in issuing a request over the network.
transition_to_state(State::Complete);
@ -446,7 +446,7 @@ void Request::handle_dns_lookup_state()
dbgln("Request::handle_dns_lookup_state: DNS lookup failed for '{}'", host);
self.m_network_error = Requests::NetworkError::UnableToResolveHost;
self.transition_to_state(State::Error);
} else if (first_is_one_of(self.m_type, Type::Fetch, Type::BackgroundRevalidation)) {
} else if (first_is_one_of(self.m_type, RequestType::Fetch, RequestType::BackgroundRevalidation)) {
self.m_dns_result = move(dns_result);
self.transition_to_state(State::RetrieveCookie);
} else {
@ -617,7 +617,7 @@ void Request::handle_fetch_state()
void Request::handle_complete_state()
{
if (m_type == Type::Fetch) {
if (m_type == RequestType::Fetch) {
VERIFY(m_curl_result_code.has_value());
// HTTPS servers might terminate their connection without proper notice of shutdown - i.e. they do not send
@ -650,7 +650,7 @@ void Request::handle_complete_state()
void Request::handle_error_state()
{
if (m_type == Type::Fetch) {
if (m_type == RequestType::Fetch) {
// FIXME: Implement timing info for failed requests.
m_client.async_request_finished(m_request_id, m_bytes_transferred_to_client, {}, m_network_error.value_or(Requests::NetworkError::Unknown));
}
@ -733,7 +733,7 @@ size_t Request::on_data_received(void* buffer, size_t size, size_t nmemb, void*
ErrorOr<void> Request::inform_client_request_started()
{
if (m_type == Type::BackgroundRevalidation)
if (m_type == RequestType::BackgroundRevalidation)
return {};
auto request_pipe = RequestPipe::create();
@ -767,7 +767,7 @@ void Request::transfer_headers_to_client_if_needed()
}
}
if (m_type == Type::BackgroundRevalidation)
if (m_type == RequestType::BackgroundRevalidation)
return;
if (m_disk_cache.has_value() && m_disk_cache->mode() == HTTP::DiskCache::Mode::Testing) {
@ -805,7 +805,7 @@ ErrorOr<void> Request::write_queued_bytes_without_blocking()
m_cache_entry_writer.clear();
};
if (m_type == Type::BackgroundRevalidation) {
if (m_type == RequestType::BackgroundRevalidation) {
write_bytes_to_disk_cache(bytes_to_send.size());
MUST(m_response_buffer.discard(bytes_to_send.size()));
@ -849,11 +849,11 @@ ErrorOr<void> Request::write_queued_bytes_without_blocking()
bool Request::is_revalidation_request() const
{
switch (m_type) {
case Type::Fetch:
case RequestType::Fetch:
return m_cache_entry_reader.has_value() && m_cache_entry_reader->revalidation_type() == HTTP::CacheEntryReader::RevalidationType::MustRevalidate;
case Type::Connect:
case RequestType::Connect:
return false;
case Type::BackgroundRevalidation:
case RequestType::BackgroundRevalidation:
return m_cache_entry_reader.has_value();
}
VERIFY_NOT_REACHED();
@ -861,7 +861,7 @@ bool Request::is_revalidation_request() const
ErrorOr<void> Request::revalidation_failed()
{
if (m_type == Type::BackgroundRevalidation && m_disk_cache->mode() == HTTP::DiskCache::Mode::Testing)
if (m_type == RequestType::BackgroundRevalidation && m_disk_cache->mode() == HTTP::DiskCache::Mode::Testing)
m_response_headers->set({ HTTP::TEST_CACHE_REVALIDATION_STATUS_HEADER, "expired"sv });
m_cache_entry_reader->revalidation_failed();

View file

@ -23,6 +23,7 @@
#include <RequestServer/CacheLevel.h>
#include <RequestServer/Forward.h>
#include <RequestServer/RequestPipe.h>
#include <RequestServer/RequestType.h>
struct curl_slist;
@ -69,14 +70,8 @@ public:
virtual ~Request() override;
enum class Type : u8 {
Fetch,
Connect,
BackgroundRevalidation,
};
u64 request_id() const { return m_request_id; }
Type type() const { return m_type; }
RequestType type() const { return m_type; }
URL::URL const& url() const { return m_url; }
virtual void notify_request_unblocked(Badge<HTTP::DiskCache>) override;
@ -129,7 +124,7 @@ private:
Request(
u64 request_id,
Type type,
RequestType type,
Optional<HTTP::DiskCache&> disk_cache,
HTTP::CacheMode cache_mode,
ConnectionFromClient& client,
@ -180,7 +175,7 @@ private:
Requests::RequestTimingInfo acquire_timing_info() const;
u64 m_request_id { 0 };
Type m_type { Type::Fetch };
RequestType m_type { RequestType::Fetch };
State m_state { State::Init };
Optional<HTTP::DiskCache&> m_disk_cache;

View file

@ -0,0 +1,19 @@
/*
* Copyright (c) 2026, Tim Flynn <trflynn89@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Types.h>
namespace RequestServer {
enum class RequestType : u8 {
Fetch,
Connect,
BackgroundRevalidation,
};
}