How to use the popsicle.createTransport function in popsicle

To help you get started, we’ve selected a few popsicle 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 blakeembrey / node-scrappy / src / scrapers / html.ts View on Github external
)

          resolve.push(req)
        }
      }

      if (options.fallbackOnFavicon !== false) {
        if (result.html && result.html.icons == null) {
          const faviconUrl = resolveUrl(contentUrl, '/favicon.ico')

          const req = get({
            url: faviconUrl,
            headers: {
              'User-Agent': options.userAgent
            },
            transport: createTransport({ type: 'stream' })
          })
            .use(status(200))

          const res = req.then(
            (res) => {
              // Initialize the favicon.
              result.html.icons = [{
                url: faviconUrl,
                type: parse(res.get('content-type')).type
              }]

              // Abort immediately response.
              res.body.on('error', (): void => undefined)
              req.abort()
            },
            () => {/* Noop request/response errors. */}
github blakeembrey / node-htmlmetaparser / scripts / fixtures.js View on Github external
function fetch () {
    console.log('Fetching "' + fixtureUrl + '"...')

    return popsicle.request({
      url: fixtureUrl,
      transport: popsicle.createTransport({
        type: 'buffer',
        jar: popsicle.jar(),
        maxBufferSize: 20 * 1000 * 1000
      })
    })
      .then(function (res) {
        return mkdir(dir)
          .then(function () {
            console.log('Writing "' + filename + '"...')

            const meta = {
              originalUrl: fixtureUrl,
              url: res.url,
              headers: res.headers,
              status: res.status,
              statusText: res.statusText
github SwellRT / swellrt / pad / node_modules / typings / node_modules / typings-core / node_modules / popsicle-proxy-agent / dist / index.spec.js View on Github external
t.test('support no proxy', function (t) {
        var proxy = createProxy({
            proxy: proxyServer.url(),
            noProxy: url_1.parse(server.url()).hostname
        });
        return popsicle_1.request({
            url: server.url(),
            transport: popsicle_1.createTransport({
                agent: proxy(server.url())
            })
        })
            .then(function (res) {
            t.equal(res.status, 200);
            t.equal(res.body, 'server /');
        });
    });
    t.test('after', function (t) {
github AraiEzzra / DDKCORE / backlog / modules / dapps.js View on Github external
library.logger.info(dapp.transactionId, `Downloading: ${dapp.link}`);

                function cleanup(err) {
                    library.logger.error(dapp.transactionId, `Download failed: ${err.message}`);

                    fs.exists(tmpPath, (exists) => {
                        if (exists) {
                            fs.unlink(tmpPath);
                        }
                        return setImmediate(serialCb, err.message);
                    });
                }

                const request = popsicle.get({
                    url: dapp.link,
                    transport: popsicle.createTransport({ type: 'stream' })
                });

                request.then((res) => {
                    if (res.status !== 200) {
                        return setImmediate(serialCb, ['Received bad response code', res.status].join(' '));
                    }

                    const stream = fs.createWriteStream(tmpPath);

                    stream.on('error', cleanup);

                    stream.on('finish', () => {
                        library.logger.info(dapp.transactionId, 'Finished downloading');
                        stream.close(serialCb);
                    });
github RiseVision / rise-node / modules / dapps.js View on Github external
performDownload: function (serialCb) {
			library.logger.info(dapp.transactionId, 'Downloading: ' + dapp.link);

			function cleanup (err) {
				library.logger.error(dapp.transactionId, 'Download failed: ' + err.message);

				fs.exists(tmpPath, function (exists) {
					if (exists) { fs.unlink(tmpPath); }
					return setImmediate(serialCb, err.message);
				});
			}

			var request = popsicle.get({
				url: dapp.link,
				transport: popsicle.createTransport({type: 'stream'})
			});

			request.then(function (res) {
				if (res.status !== 200) {
					return setImmediate(serialCb, ['Received bad response code', res.status].join(' '));
				}

				var stream = fs.createWriteStream(tmpPath);

				stream.on('error', cleanup);

				stream.on('finish', function () {
					library.logger.info(dapp.transactionId, 'Finished downloading');
					stream.close(serialCb);
				});
github SwellRT / swellrt / pad / node_modules / typings / node_modules / typings-core / dist / utils / fs.js View on Github external
exports.readHttp = throat(5, function readHttp(url) {
    var rejectUnauthorized = rc_1.default.rejectUnauthorized, ca = rc_1.default.ca, key = rc_1.default.key, cert = rc_1.default.cert, userAgent = rc_1.default.userAgent;
    return popsicle.get({
        url: url,
        headers: {
            'User-Agent': template(userAgent, {
                nodeVersion: process.version,
                platform: process.platform,
                arch: process.arch,
                typingsVersion: pkg.version
            })
        },
        transport: popsicle.createTransport({
            ca: ca,
            key: key,
            cert: cert,
            agent: exports.proxy(url),
            rejectUnauthorized: rejectUnauthorized
        })
    })
        .use(popsicleStatus(200))
        .use(function (request, next) {
        if (request.Url.host === registryURL.host) {
            if (store_1.default.get('clientId')) {
                request.set('Typings-Client-Id', store_1.default.get('clientId'));
            }
            return next().then(function (response) {
                if (response.get('Typings-Client-Id')) {
                    store_1.default.set('clientId', response.get('Typings-Client-Id'));
github RiseVision / rise-node / packages / core-p2p / src / transport.ts View on Github external
peer: BasePeerType,
    options: PeerRequestOptions
  ): Promise<{ body: T; peer: PeerType }> {
    const url = options.url;
    const thePeer = this.peersLogic.create(peer);
    const req = {
      body: options.data,
      headers: {
        ...(this.systemModule.headers as any),
        accept: 'application/octet-stream',
        'content-type': 'application/octet-stream',
        ...options.headers,
      },
      method: options.method,
      timeout: this.appConfig.peers.options.timeout,
      transport: popsicle.createTransport({ type: 'buffer' }),
      url: `http://${peer.ip}:${peer.port}${url}`,
    };

    const parsingPlugin = (
      request: popsicle.Request,
      next: () => Promise
    ) => {
      return next().then((response) => response);
    };

    let res: popsicle.Response;
    try {
      res = await promiseRetry(
        (retry) =>
          popsicle
            .request(req)
github ranjithprabhuk / ng2-Dashboard / node_modules / typings-core / dist / utils / fs.js View on Github external
exports.readHttp = throat(5, function readHttp(url) {
    var rejectUnauthorized = rc_1.default.rejectUnauthorized, ca = rc_1.default.ca, key = rc_1.default.key, cert = rc_1.default.cert, userAgent = rc_1.default.userAgent;
    return popsicle.get({
        url: url,
        headers: {
            'User-Agent': template(userAgent, {
                nodeVersion: process.version,
                platform: process.platform,
                arch: process.arch,
                typingsVersion: pkg.version
            })
        },
        transport: popsicle.createTransport({
            ca: ca,
            key: key,
            cert: cert,
            agent: exports.proxy(url),
            rejectUnauthorized: rejectUnauthorized
        })
    })
        .use(popsicleStatus(200))
        .use(function (request, next) {
        if (request.Url.host === registryURL.host) {
            if (store_1.default.get('clientId')) {
                request.set('Typings-Client-Id', store_1.default.get('clientId'));
            }
            return next().then(function (response) {
                if (response.get('Typings-Client-Id')) {
                    store_1.default.set('clientId', response.get('Typings-Client-Id'));
github ShiftNrg / shift / modules / dapps.js View on Github external
performDownload: function (serialCb) {
			library.logger.info(dapp.transactionId, 'Downloading: ' + dapp.link);

			function cleanup (err) {
				library.logger.error(dapp.transactionId, 'Download failed: ' + err.message);

				fs.exists(tmpPath, function (exists) {
					if (exists) { fs.unlink(tmpPath); }
					return setImmediate(serialCb, err.message);
				});
			}

			var request = popsicle.get({
				url: dapp.link,
				transport: popsicle.createTransport({type: 'stream'})
			});

			request.then(function (res) {
				if (res.status !== 200) {
					return setImmediate(serialCb, ['Received bad response code', res.status].join(' '));
				}

				var stream = fs.createWriteStream(tmpPath);

				stream.on('error', cleanup);

				stream.on('finish', function () {
					library.logger.info(dapp.transactionId, 'Finished downloading');
					stream.close(serialCb);
				});