Creates a new Multi instance.
Optionaloptions: MultiOptionsOptional configuration for the Multi instance
// Use default settings (notifications enabled if libcurl >= 8.17.0)
const multi = new Multi()
// Explicitly enable notifications (recommended for libcurl >= 8.17.0)
const multiWithNotifications = new Multi({ shouldUseNotificationsApi: true })
// Use traditional polling (compatible with all libcurl versions)
const multiWithPolling = new Multi({ shouldUseNotificationsApi: false })
Adds an Easy handle to be managed by this instance.
The request will start right after calling this method.
Official libcurl documentation: curl_multi_add_handle()
This will be eventually removed in favor of just using perform to add handles to the multi handle.
Closes this multi handle.
After the handle has been closed it must not be used again.
This is basically the same than curl_multi_cleanup()
Returns the number of 'Easy' handles that are currently inside this instance
Allow to provide a callback that will be called when there are new information about the handles inside this instance.
This is basically an abstraction over curl_multi_info_read()
Pass null to remove the current callback set.
Adds an Easy handle to this Multi instance and returns a promise
that resolves when the request completes successfully, or rejects with a CurlError if it fails.
This is the modern, promise-based alternative to using addHandle
with onMessage.
The returned promise will:
code property with the CurlCode value) on failureThe Easy handle to perform the request with
A promise that resolves with the Easy handle or rejects with a CurlError
const multi = new Multi()
const easy = new Easy()
easy.setOpt('URL', 'https://example.com')
try {
await multi.perform(easy)
console.log('Request completed successfully')
} catch (error) {
console.error('Request failed with code:', error.code)
}
This does what curl_multi_add_handle() does.
Removes an Easy handle that was inside this instance.
Official libcurl documentation: curl_multi_remove_handle()
Notice, removing a handle that is being performed will result in the original promise returned by perform being rejected.
Sets the PIPELINING option.
Official libcurl documentation: curl_multi_setopt()
Sets the PUSHFUNCTION option.
You must not use the Http2PushFrameHeaders object outside
of this callback, doing so will try to use memory that libcurl has already
freed and, in the best case scenario, will cause a segmentation fault.
In case you have denied the push, you must also not use the duplicatedHandle
outside of this callback, as libcurl would already have closed it and you would
try to access memory that has been freed.
Errors thrown inside this callback will have the same effect than returning CurlPush.Deny.
Per a libcurl limitation, there is no direct way to cancel the connection from inside this callback, a possible workaround is to return an error from another callback, like the progress one.
Official libcurl documentation: curl_multi_setopt()
Sets options on this instance.
Use Curl.option for predefined constants.
Official libcurl documentation: curl_multi_setopt()
Returns a description for the given error code.
Official libcurl documentation: curl_multi_strerror()
Multiclass that acts as an wrapper around the native libcurl multi handle.Using this class instead of just the Easy allows one to run requests asynchronously.
For usage see examples/04-multi.js
The Curl class uses one of this internally to provide asynchronous usage of the library.