Skip to content

Share Interface

Qriist edited this page Sep 16, 2026 · 1 revision

The Share interface allows multiple easy handles to share state — cookies, DNS cache, or SSL session data — through a common share_handle.

Creating a Share Handle

share_handle := curl.ShareInit()

Enabling Sharing

ShareSetOpt configures what is shared. The option name and value follow libcurl's CURLSHOPT_* definitions:

curl.ShareSetOpt("SHARE", "COOKIE", share_handle)

For the full list of shareable data types and options, see the libcurl share interface reference.

Associating Handles

AddEasyToShare links an easy handle to the share handle. RemoveEasyFromShare disassociates it:

curl.AddEasyToShare(easyA, share_handle)
curl.AddEasyToShare(easyB, share_handle)

Cookie Sharing Example

The most common use case is sharing cookies across multiple requests:

easyA := curl.EasyInit()
easyB := curl.EasyInit()

share_handle := curl.ShareInit()
curl.ShareSetOpt("SHARE", "COOKIE", share_handle)
curl.AddEasyToShare(easyA, share_handle)
curl.AddEasyToShare(easyB, share_handle)

; Set a cookie via easyA
; COOKIEFILE must be set AFTER ShareSetOpt
curl.SetOpt("COOKIEFILE", "", easyA)
curl.SetOpt("URL", "https://httpbin.org/cookies/set?tidbit=is%20a%20cookie", easyA)
curl.Sync(easyA)

; Read the cookie via easyB — it sees what easyA set
curl.SetOpt("COOKIEFILE", "", easyB)
curl.SetOpt("URL", "https://httpbin.org/cookies", easyB)
curl.Sync(easyB)

body := curl.GetLastBody(, easyB)
; body contains the cookie set by easyA

Ordering note: COOKIEFILE must be set on the easy handle after ShareSetOpt has configured the share handle. Setting it before will not participate in the shared cookie store.

Cleanup

ShareCleanup releases the share handle. Easy handles remain usable but lose their shared state:

curl.ShareCleanup(share_handle)

Where to Go Next

Clone this wiki locally