Truly independent web browser
/*
* Copyright (c) 2024, Andrew Kaster <[email protected]>
* Copyright (c) 2025, Tim Flynn <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
// Include this header instead of <curl/curl.h>. Only include this header from .cpp files.
#include <AK/ByteString.h>
#include <AK/Error.h>
#include <AK/StringView.h>
#include <LibDNS/Resolver.h>
#include <LibRequests/NetworkError.h>
#if defined(AK_OS_WINDOWS)
# include <AK/Windows.h> // Needed because curl.h includes winsock2.h
#endif
#include <curl/curl.h>
namespace RequestServer {
class AIACollector;
// CURLOPT_RESOLVE entries look like "[+]HOST:PORT:ADDRESS[,ADDRESS]", and "-HOST:PORT" removes an entry, so a host
// beginning with either sign cannot be pinned. Callers must not resolve such hosts through the resolve list at all.
bool can_pin_host_in_curl_resolve_list(StringView host);
ByteString build_curl_resolve_list(DNS::LookupResult const& dns_result, StringView host, u16 port);
// A CURLOPT_CONNECT_TO entry pinning one request to a single address out of the resolved pool, so that several
// requests to the same host can be spread across the addresses it resolved to instead of all piling onto whichever
// one libcurl would pick. Empty when there is only one address, i.e. nothing to spread over.
Optional<ByteString> build_curl_connect_to_entry(DNS::LookupResult const& dns_result, StringView host, u16 port, u32 address_index);
Requests::NetworkError curl_code_to_network_error(int code);
ErrorOr<void> initialize_libcurl();
// The caller keeps the collector alive until the handle is cleaned up, including if the TLS handshake fails.
CURLcode configure_certificate_verification(CURL*, AIACollector&);
// A CURLOPT_SSL_CTX_FUNCTION. Its CURLOPT_SSL_CTX_DATA is the handle's AIACollector.
CURLcode configure_ssl_context(CURL*, void* ssl_context, void* aia_collector);
}