Skip to content

SSL Sessions

Qriist edited this page Sep 17, 2026 · 1 revision

SSL session data can be exported and imported to enable resumption across transfers or script executions. This reduces TLS handshake overhead on subsequent connections to the same server.

Enabling Session Sharing

SSL session sharing requires a share handle configured for the SSL_SESSION type:

share_handle := curl.ShareInit()

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

As an alternative, if you don't want to manage an entire instance, you can use the default share_handle:

share_handle := curl.shareHandleMap[0][1]

The share handle must be attached to an easy handle before any transfer that should participate in session resumption:

curl.SetOpt("SHARE", share_handle)

Exporting Sessions

After a successful TLS transfer, call ExportSSLs() on the active easy handle. It returns an array of serialized session objects containing handshake state and credentials:

sslObj := curl.ExportSSLs()

This data can be serialized to JSON for storage across script runs:

sslJson := JSON.Dump(sslObj)
FileOpen("ssl_cache.json", "w").Write(sslJson)

Importing Sessions

Before performing a transfer on a target server, import previously saved sessions to accelerate the TLS handshake:

raw := FileOpen("ssl_cache.json", "r").Read()
sslObj := JSON.Load(raw)

; Applies saved sessions to the active easy handle
curl.ImportSSLs(sslObj)

curl.SetOpt("URL", "https://example.com")
curl.Sync()

Notes

  • Sessions are bound to the specific server hostname and port. Importing sessions from an unrelated domain is safely ignored by libcurl.
  • ExportSSLs captures state immediately after a transfer completes. Calling it before any TLS activity returns an empty array.
  • The underlying export callback plumbing is handled internally. You interact solely with the top-level import/export API.

Where to Go Next

Clone this wiki locally