Skip to content

Multiple Easy Handles

Qriist edited this page Sep 17, 2026 · 4 revisions

A single LibQurl() instance can manage any number of easy handles. Each handle maintains its own independent set of options, write targets, and transfer state.

Creating Handles

Init() (or its alias EasyInit()) creates a new easy handle:

easy_handle_a := curl.Init()
easy_handle_b := curl.Init()

The default handle (the first one created) is available without explicit creation. LibQurl() establishes it. You only need to call Init() when you want a second, third, or Nth handle.

Per-Handle Isolation

Options, write targets, and transfer state are all scoped to the handle. Two handles pointing at different URLs with different settings do not interfere with each other:

easy_handle_a := curl.Init()
easy_handle_b := curl.Init()

curl.SetOpt("URL", "https://example.com/page1", easy_handle_a)
curl.SetOpt("URL", "https://example.com/page2", easy_handle_b)

curl.WriteToFile("C:\downloads\page1.html", easy_handle_a)
curl.WriteToFile("C:\downloads\page2.html", easy_handle_b)

curl.Sync(easy_handle_a)
curl.Sync(easy_handle_b)

Listing Handles

ListHandles returns a plaintext listing of all currently open easy handles:

MsgBox curl.ListHandles()

Duplicating a Handle

DupeInit creates a new handle that is a logical clone of an existing one. All options are copied. Write and header callbacks are not — the new handle gets a fresh WriteToMem target internally.

Note: due to an unresolved technical issue the class manually rebuilds the easy_handle from the original stored options rather than invoking libcurl's native function. It should give identical results, however.

original := curl.Init()
curl.WriteToMem(, original)
curl.SetOpt("URL", "https://example.com/api", original)
curl.SetOpt("USERAGENT", "LibQurl/1.0", original)

; Clone the options onto a fresh handle
duped := curl.DupeInit()

; The duped handle has the same USERAGENT, the same URL, etc.
; But its write target is decoupled — it defaults to memory.
curl.SetOpt("URL", "https://example.com/api/v2", duped)

curl.Sync(original)
curl.Sync(duped)

bodyA := curl.GetLastBody(, original)
bodyB := curl.GetLastBody(, duped)

Use DupeInit when you want a fresh handle pre-configured with the same options, without re-setting each one manually.

Cleanup

Cleanup (or its alias EasyCleanup) releases a handle and all its associated callbacks:

curl.EasyCleanup(easy_handle_a)

If you clean up the last remaining easy handle, LibQurl automatically creates a fresh default so you are never left without one. See Terminology and Conventions.

Where to Go Next

Clone this wiki locally