How to use popsicle - 10 common examples

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 jcoreio / crater / test / integration / integrationTests.js View on Github external
async function navigateTo(url) {
  if (process.env.DUMP_HTTP) {
    const res = await popsicle.get(url)
    /* eslint-disable no-console */
    console.log(`GET ${url} ${res.status}`)
    console.log(res.headers)
    console.log(res.body)
    /* eslint-enable no-console */
  }
  await browser.url(url)
}
github mulesoft / osprey / test / support / utils.js View on Github external
// Set response text to "body" property to mimic popsicle v10
  // response interface.
  function responseBodyMiddleware (req, next) {
    return next().then(res => {
      return res.text().then(body => {
        res.body = body
        return res
      })
    })
  }

  var middleware = [responseBodyMiddleware, ...mware, popsicle.middleware]

  return {
    fetch: popsicle.toFetch(compose(middleware), Request)
  }
}
github mulesoft-labs / osprey-mock-service / test / utils.js View on Github external
// response interface.

  function responseBodyMiddleware (req, next) {
    return next().then(res => {
      return res.text().then(body => {
        res.body = body
        return res
      })
    })
  }

  var popsicleServerMiddleware = popsicleServer(app)
  var middleware = compose([
    responseBodyMiddleware,
    popsicleServerMiddleware,
    popsicle.middleware
  ])

  return {
    fetch: popsicle.toFetch(middleware, Request)
  }
}
github mulesoft / osprey / test / support / utils.js View on Github external
var compose = require('throwback').compose
  var Request = require('servie').Request
  var popsicle = require('popsicle')

  // Set response text to "body" property to mimic popsicle v10
  // response interface.
  function responseBodyMiddleware (req, next) {
    return next().then(res => {
      return res.text().then(body => {
        res.body = body
        return res
      })
    })
  }

  var middleware = [responseBodyMiddleware, ...mware, popsicle.middleware]

  return {
    fetch: popsicle.toFetch(compose(middleware), Request)
  }
}
github AraiEzzra / DDKCORE / src / modules / transport.js View on Github external
peer = library.logic.peers.create(peer);
    __private.headers.port = 7007;
    const req = {
        url: `http://${peer.ip}:${peer.port}${url}`,
        method: options.method,
        headers: __private.headers,
        timeout: library.config.peers.options.timeout
    };

    if (options.data) {
        req.body = options.data;
    }

    popsicle.request(req)
        .use(popsicle.plugins.parse(['json'], false))
        .then((res) => {
            if (res.status !== 200) {
                // Remove peer
                __private.removePeer({ peer, code: `ERESPONSE ${res.status}` }, `${req.method} ${req.url}`);

                return setImmediate(cb, ['Received bad response code', res.status, req.method, req.url].join(' '));
            }
            const headers = peer.applyHeaders(res.headers);

            const report = library.schema.validate(headers, schema.headers);
            if (!report) {
                // Remove peer
                console.log('EHEADERS1', report);
                __private.removePeer({ peer, code: 'EHEADERS' }, `${req.method} ${req.url}`);

                return setImmediate(cb, ['Invalid response headers', JSON.stringify(headers), req.method, req.url].join(' '));
github AraiEzzra / DDKCORE / backlog / modules / transport.js View on Github external
peer = library.logic.peers.create(peer);
    __private.headers.port = 7007;
    const req = {
        url: `http://${peer.ip}:${peer.port}${url}`,
        method: options.method,
        headers: __private.headers,
        timeout: library.config.peers.options.timeout
    };

    if (options.data) {
        req.body = options.data;
    }

    popsicle.request(req)
        .use(popsicle.plugins.parse(['json'], false))
        .then((res) => {
            if (res.status !== 200) {
                // Remove peer
                __private.removePeer({ peer, code: `ERESPONSE ${res.status}` }, `${req.method} ${req.url}`);

                return setImmediate(cb, ['Received bad response code', res.status, req.method, req.url].join(' '));
            }
            const headers = peer.applyHeaders(res.headers);

            const report = library.schema.validate(headers, schema.headers);
            if (!report) {
                // Remove peer
                console.log('EHEADERS1', report);
                __private.removePeer({ peer, code: 'EHEADERS' }, `${req.method} ${req.url}`);

                return setImmediate(cb, ['Invalid response headers', JSON.stringify(headers), req.method, req.url].join(' '));
github ShiftNrg / shift / modules / transport.js View on Github external
}

	peer = library.logic.peers.create(peer);

	var req = {
		url: 'http://' + peer.ip + ':' + peer.port + url,
		method: options.method,
		headers: __private.headers,
		timeout: library.config.peers.options.timeout
	};

	if (options.data) {
		req.body = options.data;
	}

	popsicle.request(req)
		.use(popsicle.plugins.parse(['json'], false))
		.then(function (res) {
			if (res.status !== 200) {
				// Remove peer
				__private.removePeer({peer: peer, code: 'ERESPONSE ' + res.status}, req.method + ' ' + req.url);

				return setImmediate(cb, ['Received bad response code', res.status, req.method, req.url].join(' '));
			} else {
				var headers = peer.applyHeaders(res.headers);

				var report = library.schema.validate(headers, schema.headers);
				if (!report) {
					// Remove peer
					__private.removePeer({peer: peer, code: 'EHEADERS'}, req.method + ' ' + req.url);

					return setImmediate(cb, ['Invalid response headers', JSON.stringify(headers), req.method, req.url].join(' '));
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-scrappy / src / scrape / support.ts View on Github external
export async function makeRequest (url: string): Promise {
  const req = request({
    url,
    headers: {
      'User-Agent': 'Scrappy-LinkExpanding 1.0 (+https://github.com/blakeembrey/node-scrappy)'
    },
    use: [],
    transport: createTransport({ type: 'stream', jar: jar() })
  })

  return req.then((res) => {
    // Abort wrapper to ignore streaming errors from aborting (e.g. unzipping).
    function abort () {
      res.body.on('error', () => undefined)
      req.abort()
    }

    return {
      stream: res.body,
      headers: res.headers,
      status: res.status,
      abort: abort,
      url: res.url
    }
github blakeembrey / node-scrappy / src / scrapers / html.ts View on Github external
.then(function (result) {
      const resolve: Array> = []

      // Attach OEmbed information to entry.
      if (options.useOEmbed !== false) {
        if (oembedJsonUrl) {
          const req = get({
            url: oembedJsonUrl,
            headers: {
              'User-Agent': options.userAgent
            }
          })
            .use(status(200))
            .use(plugins.parse('json'))
            .then(
              (res) => {
                result.oembed = res.body
              },
              () => {/* Noop request/response errors. */}
            )

          resolve.push(req)
        }
      }

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

          const req = get({