aboutsummaryrefslogtreecommitdiff
path: root/src/Utility/HttpClient.c
diff options
context:
space:
mode:
authorfrosty <gabriel@bwaaa.monster>2026-06-02 18:18:45 -0400
committerfrosty <gabriel@bwaaa.monster>2026-06-02 18:18:45 -0400
commitc26a08c6a29416b3c59f1b2c9f65335b4409ce4f (patch)
treeab0a2532afe7c78efc6689611865e03bc4e9e005 /src/Utility/HttpClient.c
parent5808459c758db353d8d39df556ae42028e762321 (diff)
downloadomnisearch-c26a08c6a29416b3c59f1b2c9f65335b4409ce4f.tar.gz
fix: some attempts to resolve some issues with images
Diffstat (limited to 'src/Utility/HttpClient.c')
-rw-r--r--src/Utility/HttpClient.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/Utility/HttpClient.c b/src/Utility/HttpClient.c
index bdd2f4d..0ffb9ff 100644
--- a/src/Utility/HttpClient.c
+++ b/src/Utility/HttpClient.c
@@ -31,6 +31,17 @@ static size_t write_callback(void *contents, size_t size, size_t nmemb,
return realsize;
}
+static struct curl_slist *build_http_headers(void) {
+ struct curl_slist *headers = NULL;
+ headers = curl_slist_append(
+ headers,
+ "Accept: "
+ "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
+ headers = curl_slist_append(headers, "Accept-Language: en-US,en;q=0.5");
+ headers = curl_slist_append(headers, "DNT: 1");
+ return headers;
+}
+
HttpResponse http_get(const char *url, const char *user_agent) {
HttpResponse resp = {.memory = NULL, .size = 0, .capacity = 0};
@@ -51,16 +62,24 @@ HttpResponse http_get(const char *url, const char *user_agent) {
return resp;
}
+ struct curl_slist *headers = build_http_headers();
+
curl_easy_setopt(curl, CURLOPT_URL, url);
+ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &resp);
curl_easy_setopt(curl, CURLOPT_USERAGENT,
user_agent ? user_agent : "libcurl-agent/1.0");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
- curl_easy_setopt(curl, CURLOPT_TIMEOUT, 15L);
+ curl_easy_setopt(curl, CURLOPT_TIMEOUT, CURL_TIMEOUT_SECS);
+ curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
+ curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
+ curl_easy_setopt(curl, CURLOPT_DNS_CACHE_TIMEOUT, CURL_DNS_TIMEOUT_SECS);
+ curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
apply_proxy_settings(curl);
CURLcode res = curl_easy_perform(curl);
+ curl_slist_free_all(headers);
curl_easy_cleanup(curl);
if (res != CURLE_OK) {