CURLOPT_HSTS_CTRL(3)
β¨ CURLOPT_HSTS_CTRL β¨
okay bestie, welcome to the CURLOPT_HSTS_CTRL page of the libcurl manual β it's a Library Functions Manual entry and honestly? it's giving "small but mighty" π
πΈ NAME πΈ
CURLOPT_HSTS_CTRL β the lil option that controls HSTS behavior π
π¦ SYNOPSIS π¦
#include <curl/curl.h>
#define CURLHSTS_ENABLE (1L << 0)
#define CURLHSTS_READONLYFILE (1L << 1)
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HSTS_CTRL, long bitmask);
like, you include the header, you get those two #defined bits, and you hand a long bitmask to curl_easy_setopt on your CURL *handle. that's the whole vibe β¨
π DESCRIPTION π
so HSTS stands for HTTP Strict Transport Security, and what it means is: an HTTPS server can literally tell the client "bestie do NOT contact me again over clear-text HTTP for a certain period into the future" β and the client respects it. no cap. π ββοΈ
libcurl then automatically redirects HTTP attempts to those hosts so they use HTTPS instead. how does it remember? by libcurl retaining this knowledge in an in-memory cache. iconic behavior fr fr π§ β¨
so what you do is: populate that long bitmask with the correct set of features, and that tells libcurl exactly how to handle HSTS for the transfers using this handle. that's it, that's the whole job π
π BITS π
CURLHSTS_ENABLEβ turns on the in-memory HSTS cache for this handle. slay, the cache is live π«ΆCURLHSTS_READONLYFILEβ makes the HSTS file (if specified) read-only, which means libcurl will not save the cache to the file when it closes the handle. it's giving "look but don't touch" π
β DEFAULT β
0
(yes, zero. nothing enabled out of the box, you gotta opt in π)
π PROTOCOLS π
this functionality affects http only π¦
π₯ EXAMPLE π₯
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_HSTS_CTRL, CURLHSTS_ENABLE);
curl_easy_perform(curl);
}
}
look at that. init, set the bitmask to CURLHSTS_ENABLE, perform. main character energy tbh π
π AVAILABILITY π
Added in curl 7.74.0 β so if you're on something ancient, this is your sign to upgrade bestie π§
π 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) for the deets π
lowkey important:0= good vibes, anything else = go readlibcurl-errors(3). periodt.
π SEE ALSO π
and that's the page!! π brought to you by libcurl, dated 2026-10-12 β stay encrypted, stay iconic, and remember: HSTS is your friend π¦β¨
π¦ 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