public static function createCurlFilter($errorCodes = null)
    {
        // Only use the cURL filter if cURL is loaded.
        if (!extension_loaded('curl')) {
            return function () { return false; };
        }

        $errorCodes = $errorCodes ?: [
            CURLE_OPERATION_TIMEOUTED,
            CURLE_COULDNT_RESOLVE_HOST,
            CURLE_COULDNT_CONNECT,
            CURLE_SSL_CONNECT_ERROR,
            CURLE_GOT_NOTHING
        ];

        $errorCodes = array_fill_keys($errorCodes, 1);

        return function ($retries, AbstractTransferEvent $e) use ($errorCodes) {
            return isset($errorCodes[(int) $e->getTransferInfo('errno')]);
        };
    }