CURLOPT_WS_OPTIONS(3)
π CURLOPT_WS_OPTIONS β¨
Okay so bestie, welcome to the CURLOPT_WS_OPTIONS page from the Library Functions Manual β yes, that manual, the one with all the curl lore. This one's all about making your WebSocket behave exactly how you want it to. Sit down, grab a boba, we're getting into it π§π
πΈ NAME πΈ
CURLOPT_WS_OPTIONS β WebSocket behavior options, aka the vibe settings for your WebSocket conn πβ¨
π SYNOPSIS π
#include <curl/curl.h>
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_WS_OPTIONS, long bitmask);
π¦ DESCRIPTION π¦
So you pass a long that's a bitmask, right? And that bitmask tells libcurl about specific WebSocket behaviors. Very "here's my settings, don't ask questions" energy π
Now, if you wanna detach a WebSocket connection and use curl_ws_send(3) and curl_ws_recv(3) after the HTTP upgrade procedure β you're gonna set the CURLOPT_CONNECT_ONLY(3) option to 2L. That's the move. No cap π«Ά
β Available bits in the bitmask β
CURLWS_RAW_MODE(1) β Delivers "raw" WebSocket traffic to theCURLOPT_WRITEFUNCTION(3)callback, and reads "raw" WebSocket traffic from theCURLOPT_READFUNCTION(3)callback. And listen β in raw mode, libcurl does not handle pings or any other frame for the application. It's all you, main character πCURLWS_NOAUTOPONG(2) β Disables the automatic reply to PING messages. Which means you have to send a PONG message yourself withcurl_ws_send(3). The way this feature was added with version8.14.0β iconic π₯
π DEFAULT π
0
π PROTOCOLS π
This functionality affects ws only. That's it. That's the whole protocol list. ws and nothing else π¦
π EXAMPLE π
int main(void)
{
CURL *curl = curl_easy_init();
if(curl) {
CURLcode result;
curl_easy_setopt(curl, CURLOPT_URL, "ws://example.com/");
/* tell curl we deal with all the WebSocket magic ourselves */
curl_easy_setopt(curl, CURLOPT_WS_OPTIONS, CURLWS_RAW_MODE);
result = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
Literally the whole thing. We're handling all the WebSocket magic ourselves, bestie π§β¨
π HISTORY π
Okay so the CURLWS_RAW_MODE and CURLWS_NOAUTOPONG macros became long types in 8.16.0. Which means β before that version, a long cast was necessary when passed to curl_easy_setopt(3). Yes, an actual cast. We used to live like that ππ
πΈ AVAILABILITY πΈ
Added in curl 7.86.0 β so if you're on something ancient, sorry babe π
β¨ RETURN VALUE β¨
curl_easy_setopt(3) returns a CURLcode indicating success or error. Groundbreaking, I know.
CURLE_OK (0) means everything was OK. Non-zero means an error occurred β see libcurl-errors(3) for the full tea βπ
π«Ά SEE ALSO π«Ά
π That's the whole page bestie β go forth and configure your WebSockets with confidence. iykyk β¨
Later, legend π¦ β this page came to you from the libcurl fam, dated 2026-10-12, and it's CURLOPT_WS_OPTIONS(3) all day. Mwah π
π¦ 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