CURLOPT_ALTSVC(3)
β¨ CURLOPT_ALTSVC β¨
okay so this is the CURLOPT_ALTSVC page from the curl library functions manual, and honestly it's kind of a gem π β it's all about alt-svc cache filename, which sounds scary but bestie it's literally just "where do we keep the little notes file". let's get into it π«Ά
πΈ SYNOPSIS πΈ
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_ALTSVC, char *filename);
π DESCRIPTION π
so you pass in a pointer to a filename and that tells libcurl "hey, use THIS file as the Alt-Svc cache" β meaning it reads the existing cache contents from it, and possibly also writes back to it after a transfer. β¨
the one exception? if CURLALTSVC_READONLYFILE is set in CURLOPT_ALTSVC_CTRL(3). then it's read-only, no writing back, respect the boundary π
if you pass a blank filename ("") then libcurl just... doesn't load from a file at all. bye file, we don't know her π
good news: the application does not have to keep the string around after setting this option. libcurl's got it, you can let go π¦
and if you set this option multiple times? the last set string wins, it overrides the previous ones. main character energy only π set it to NULL to disable its use again.
π₯ SECURITY CONCERNS π₯
no cap, this part matters so listen up:
libcurl cannot fully protect against attacks where an attacker has write access to the same directory where it is directed to save files. and it's particularly sensitive if you save files using elevated privileges. π like, be careful bestie.
also β libcurl creates the file to store the alt-svc cache in using default file permissions. meaning that on *nix systems you may need to restrict your umask to prevent other users on the same system from accessing the file. π
fr fr, check your umask. this is not a drill.
π DEFAULT π
NULL. the alt-svc cache is not read nor written to file. a whole lot of nothing, iconic π
π PROTOCOLS π
this functionality affects http only. that's it, that's the whole section π
β EXAMPLE β
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_ALTSVC_CTRL, CURLALTSVC_H1);
curl_easy_setopt(curl, CURLOPT_ALTSVC, "altsvc-cache.txt");
curl_easy_perform(curl);
}
}
look at that. clean. no notes. π§
π¦ HISTORY π¦
okay tiny lore drop: the CURLALTSVC_* macros became long types in 8.16.0. prior to this version a long cast was necessary when passed to curl_easy_setopt(3). so if you're on ancient curl, cast it. slay π
π FILE FORMAT π
it's a text based file, one line per alt-svc entry, and each line consists of nine space-separated fields. nine!! count 'em π
an example line could look like
h2 www.example.com 8443 h3 second.example.com 443 "20190808 06:18:37" 1 0
the fields of that line are:
h2β ALPN id for the source originwww.example.compβ Hostname for the source origin8443β Port number for the source originh3β ALPN id for the destination hostsecond.example.comβ Hostname for the destination host443β Port number for the destination host2019*β Expiration date and time of this entry within double quotes. the date format is"YYYYMMDD HH:MM:SS"and the time zone is GMT.1β Boolean (1or0) if "persist" was set for this entry0β Integer priority value (not currently used)
no I did not typo www.example.comp, that's literally what the page says, we keep the facts exactly as they are π
π AVAILABILITY π
added in curl 7.64.1 πΈ
π«Ά 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, see libcurl-errors(3). simple as that β¨
π SEE ALSO π
and that's the whole page bestie!! mwah π this was libcurl, dated 2026-10-12 β go forth and cache your alt-svcs responsibly πβ¨π¦
π¦ 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