mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
RequestServer: Move some cURL utilities to their own file
This will allow more easily using these from other files. This also lets us hide the Windows.h header necessity in a single location, instead of needing to remember to include it everywhre we would otherwise include <curl/curl.h>.
This commit is contained in:
parent
7450da5556
commit
1216a2f952
Notes:
github-actions[bot]
2025-10-28 10:54:33 +00:00
Author: https://github.com/trflynn89
Commit: 1216a2f952
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6579
Reviewed-by: https://github.com/ayeteadoe
Reviewed-by: https://github.com/konradekk
6 changed files with 91 additions and 60 deletions
|
|
@ -17,18 +17,12 @@
|
|||
#include <LibTextCodec/Decoder.h>
|
||||
#include <LibWebSocket/ConnectionInfo.h>
|
||||
#include <LibWebSocket/Message.h>
|
||||
#include <RequestServer/CURL.h>
|
||||
#include <RequestServer/Cache/DiskCache.h>
|
||||
#include <RequestServer/ConnectionFromClient.h>
|
||||
#include <RequestServer/Resolver.h>
|
||||
#include <RequestServer/WebSocketImplCurl.h>
|
||||
|
||||
#ifdef AK_OS_WINDOWS
|
||||
// needed because curl.h includes winsock2.h
|
||||
# include <AK/Windows.h>
|
||||
#endif
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
namespace RequestServer {
|
||||
|
||||
static HashMap<int, RefPtr<ConnectionFromClient>> s_connections;
|
||||
|
|
@ -38,26 +32,6 @@ static long s_connect_timeout_seconds = 90L;
|
|||
|
||||
Optional<DiskCache> g_disk_cache;
|
||||
|
||||
ByteString build_curl_resolve_list(DNS::LookupResult const& dns_result, StringView host, u16 port)
|
||||
{
|
||||
StringBuilder resolve_opt_builder;
|
||||
resolve_opt_builder.appendff("{}:{}:", host, port);
|
||||
auto first = true;
|
||||
for (auto& addr : dns_result.cached_addresses()) {
|
||||
auto formatted_address = addr.visit(
|
||||
[&](IPv4Address const& ipv4) { return ipv4.to_byte_string(); },
|
||||
[&](IPv6Address const& ipv6) { return MUST(ipv6.to_string()).to_byte_string(); });
|
||||
if (!first)
|
||||
resolve_opt_builder.append(',');
|
||||
first = false;
|
||||
resolve_opt_builder.append(formatted_address);
|
||||
}
|
||||
|
||||
dbgln_if(REQUESTSERVER_DEBUG, "RequestServer: Resolve list: {}", resolve_opt_builder.string_view());
|
||||
|
||||
return resolve_opt_builder.to_byte_string();
|
||||
}
|
||||
|
||||
struct ConnectionFromClient::ActiveRequest : public Weakable<ActiveRequest> {
|
||||
CURLM* multi { nullptr };
|
||||
CURL* easy { nullptr };
|
||||
|
|
@ -674,32 +648,6 @@ void ConnectionFromClient::issue_network_request(i32 request_id, ByteString meth
|
|||
}
|
||||
#endif
|
||||
|
||||
static Requests::NetworkError map_curl_code_to_network_error(CURLcode const& code)
|
||||
{
|
||||
switch (code) {
|
||||
case CURLE_COULDNT_RESOLVE_HOST:
|
||||
return Requests::NetworkError::UnableToResolveHost;
|
||||
case CURLE_COULDNT_RESOLVE_PROXY:
|
||||
return Requests::NetworkError::UnableToResolveProxy;
|
||||
case CURLE_COULDNT_CONNECT:
|
||||
return Requests::NetworkError::UnableToConnect;
|
||||
case CURLE_OPERATION_TIMEDOUT:
|
||||
return Requests::NetworkError::TimeoutReached;
|
||||
case CURLE_TOO_MANY_REDIRECTS:
|
||||
return Requests::NetworkError::TooManyRedirects;
|
||||
case CURLE_SSL_CONNECT_ERROR:
|
||||
return Requests::NetworkError::SSLHandshakeFailed;
|
||||
case CURLE_PEER_FAILED_VERIFICATION:
|
||||
return Requests::NetworkError::SSLVerificationFailed;
|
||||
case CURLE_URL_MALFORMAT:
|
||||
return Requests::NetworkError::MalformedUrl;
|
||||
case CURLE_BAD_CONTENT_ENCODING:
|
||||
return Requests::NetworkError::InvalidContentEncoding;
|
||||
default:
|
||||
return Requests::NetworkError::Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
static Requests::RequestTimingInfo get_timing_info_from_curl_easy_handle(CURL* easy_handle)
|
||||
{
|
||||
/*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue