How to use node-libcurl - 10 common examples

To help you get started, we’ve selected a few node-libcurl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zeit / pkg / test / test-79-npm / node-libcurl / node-libcurl.js View on Github external
'use strict';

// apt-get install libcurl4-openssl-dev

// IF YOU USE 32-BIT NODEJS:
// patch /usr/include/curl/curlbuild.h
// #define CURL_SIZEOF_LONG 4
// #define CURL_SIZEOF_CURL_OFF_T 4

var Curl = require('node-libcurl').Curl;
var curl = new Curl();
curl.setOpt('URL', 'www.yandex.ru');
curl.setOpt('FOLLOWLOCATION', true);
curl.on('end', function (status) {
  if (status === 200) {
    console.log('ok');
  }
  this.close(); // eslint-disable-line no-invalid-this
});
curl.perform();
github do-web / curl-request / index.js View on Github external
this.setProxy = (host, proxyType) => {
        this.curl.setOpt(Curl.option.PROXY, host);

        // SOCKS5 default
        if (typeof proxyType === 'undefined') {
            this.curl.setOpt(Curl.option.PROXYTYPE, Curl.proxy.SOCKS5_HOSTNAME);
        } else {
            this.curl.setOpt(Curl.option.PROXYTYPE, proxyType);
        }

        return this;
    };
github do-web / curl-request / index.js View on Github external
this.setProxy = (host, proxyType) => {
        this.curl.setOpt(Curl.option.PROXY, host);

        // SOCKS5 default
        if (typeof proxyType === 'undefined') {
            this.curl.setOpt(Curl.option.PROXYTYPE, Curl.proxy.SOCKS5_HOSTNAME);
        } else {
            this.curl.setOpt(Curl.option.PROXYTYPE, proxyType);
        }

        return this;
    };
github do-web / curl-request / index.js View on Github external
module.exports = function () {

    this['default'] = {
        torControlHost: 'localhost',
        torControlPort: 9051,
        autoParse: true, // content-type detect -> json
        verbose: false,
        useProxy: false,
        proxy: 'localhost:9050',
        proxyType: Curl.proxy.SOCKS5_HOSTNAME
    };

    this.libcurl = Curl;

    this.curl = new Curl();

    this.newTorIdentity = () => {
        let client = new Net.Socket();
        client.connect(this['default'].torControlPort, this['default'].torControlHost, () => {
            client.write('authenticate\nsignal newnym\nquit');
        });
    };

    this._setUrl = (url) => {
        this.curl.setOpt(Curl.option.URL, url);
        return this;
github vendure-ecommerce / vendure / packages / testing / src / simple-graphql-client.ts View on Github external
{
                    name: 'operations',
                    contents: JSON.stringify(postData.operations),
                },
                {
                    name: 'map',
                    contents:
                        '{' +
                        Object.entries(postData.map)
                            .map(([i, path]) => `"${i}":["${path}"]`)
                            .join(',') +
                        '}',
                },
                ...postData.filePaths,
            ];
            curl.setOpt(Curl.option.URL, this.apiUrl);
            curl.setOpt(Curl.option.VERBOSE, false);
            curl.setOpt(Curl.option.TIMEOUT_MS, 30000);
            curl.setOpt(Curl.option.HTTPPOST, processedPostData);
            curl.setOpt(Curl.option.HTTPHEADER, [
                `Authorization: Bearer ${this.authToken}`,
                `${this.vendureConfig.channelTokenKey}: ${this.channelToken}`,
            ]);
            curl.perform();
            curl.on('end', (statusCode: any, body: any) => {
                curl.close();
                const response = JSON.parse(body);
                if (response.errors && response.errors.length) {
                    const error = response.errors[0];
                    console.log(JSON.stringify(error.extensions, null, 2));
                    throw new Error(error.message);
                }
github vendure-ecommerce / vendure / packages / testing / src / simple-graphql-client.ts View on Github external
{
                    name: 'map',
                    contents:
                        '{' +
                        Object.entries(postData.map)
                            .map(([i, path]) => `"${i}":["${path}"]`)
                            .join(',') +
                        '}',
                },
                ...postData.filePaths,
            ];
            curl.setOpt(Curl.option.URL, this.apiUrl);
            curl.setOpt(Curl.option.VERBOSE, false);
            curl.setOpt(Curl.option.TIMEOUT_MS, 30000);
            curl.setOpt(Curl.option.HTTPPOST, processedPostData);
            curl.setOpt(Curl.option.HTTPHEADER, [
                `Authorization: Bearer ${this.authToken}`,
                `${this.vendureConfig.channelTokenKey}: ${this.channelToken}`,
            ]);
            curl.perform();
            curl.on('end', (statusCode: any, body: any) => {
                curl.close();
                const response = JSON.parse(body);
                if (response.errors && response.errors.length) {
                    const error = response.errors[0];
                    console.log(JSON.stringify(error.extensions, null, 2));
                    throw new Error(error.message);
                }
                resolve(response.data);
            });

            curl.on('error', (err: any) => {
github vendure-ecommerce / vendure / packages / testing / src / simple-graphql-client.ts View on Github external
return new Promise((resolve, reject) => {
            const curl = new Curl();

            const postData = createUploadPostData(mutation, filePaths, mapVariables);
            const processedPostData = [
                {
                    name: 'operations',
                    contents: JSON.stringify(postData.operations),
                },
                {
                    name: 'map',
                    contents:
                        '{' +
                        Object.entries(postData.map)
                            .map(([i, path]) => `"${i}":["${path}"]`)
                            .join(',') +
                        '}',
                },
github do-web / curl-request / index.js View on Github external
this.head = (url) => {
        this._setUrl(url);
        this.curl.setOpt(Curl.option.CUSTOMREQUEST, 'HEAD');
        return this._submit();
    };
github mikearnaldi / matechs-effect / packages / http-client-libcurl / src / index.ts View on Github external
T.async(done => {
              const req = new C.Curl();
              const reqHead = [
                ...(isJson(requestType)
                  ? ["Content-Type: application/json"]
                  : []),
                ...pipe(
                  headers,
                  R.collect((k, v) => `${k}: ${v}`)
                )
              ];

              req.setOpt("URL", url);
              req.setOpt("CAINFO", caPath);
              req.setOpt("FOLLOWLOCATION", 1);
              req.setOpt("VERBOSE", 0);
              req.setOpt("SSL_VERIFYHOST", 2);
              req.setOpt("SSL_VERIFYPEER", 1);
github do-web / curl-request / index.js View on Github external
this._reset = () => {
        this.curl = new Curl();
    };

node-libcurl

The fastest http(s) client (and much more) for Node.js - Node.js bindings for libcurl

MIT
Latest version published 9 months ago

Package Health Score

42 / 100
Full package analysis