CURLOPT_REQUEST_TARGET(3)
π CURLOPT_REQUEST_TARGET(3) β the libcurl glow-up
okay so real talk: you're reading a page from the Library Functions Manual, section 3, and the star of the show is CURLOPT_REQUEST_TARGET. It's a libcurl thing. Buckle up bestie, this one's short but it's mighty. β¨
β¨ NAME β¨
CURLOPT_REQUEST_TARGET β an alternative target for this request. like, you get to pick what goes in the request line instead of letting the URL decide. main character energy fr. π
π¦ SYNOPSIS π¦
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_REQUEST_TARGET, string);
that's it. that's the whole vibe. π«Ά
πΈ DESCRIPTION πΈ
so you pass a char pointer to string and libcurl lowkey uses it in the upcoming request instead of the path it extracted from the URL. you're basically overriding the path. not me giving you that much power, but here we are. π
and listen β libcurl passes on the verbatim string in its request, without any filter or other safe guards. no vibes check, no nothing. that includes white space and control characters. like it will genuinely just send whatever you hand it. π so maybe don't hand it chaos?
using this option multiple times makes the last set string override the previous ones. last one wins, periodt. set it to NULL to disable its use again β a lil reset button for your soul. π
the application does not have to keep the string around after setting this option. libcurl copies it, so you can let it go. iconic behaviour honestly. π
β DEFAULT β
NULL
(yes, nothing. no target override until you say so. the default is defaulting. π)
π§ PROTOCOLS π§
this functionality affects http only. yep. http and nothing else, no cap. π¦
π₯ EXAMPLE π₯
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/*");
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "OPTIONS");
/* issue an OPTIONS * request (no leading slash) */
curl_easy_setopt(curl, CURLOPT_REQUEST_TARGET, "*");
/* Perform the request */
curl_easy_perform(curl);
}
}
see that note? no leading slash. just "*". don't add a slash, don't be extra, it's giving minimalism. π
π AVAILABILITY π
added in curl 7.55.0 β so if you're on something ancient, bestie, upgrade. π
π RETURN VALUE π
curl_easy_setopt(3) returns a CURLcode indicating success or error.
CURLE_OK (0) means everything was OK. non-zero means an error occurred β go check libcurl-errors(3) and let it explain itself. π€
π SEE ALSO π
read them, they're all connected, iykyk. πΈ
okay that's the page!! brought to you by libcurl, dated 2026-10-12, CURLOPT_REQUEST_TARGET(3) β mwah, go slay your requests bestie πβ¨π«Ά
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms