How to use the minipass-fetch.Headers function in minipass-fetch

To help you get started, we’ve selected a few minipass-fetch 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 npm / make-fetch-happen / cache.js View on Github external
}).then(info => {
      if (info && info.metadata && matchDetails(req, {
        url: info.metadata.url,
        reqHeaders: new fetch.Headers(info.metadata.reqHeaders),
        resHeaders: new fetch.Headers(info.metadata.resHeaders),
        cacheIntegrity: info.integrity,
        integrity: opts && opts.integrity
      })) {
        const resHeaders = new fetch.Headers(info.metadata.resHeaders)
        addCacheHeaders(resHeaders, this._path, key, info.integrity, info.time)
        if (req.method === 'HEAD') {
          return new fetch.Response(null, {
            url: req.url,
            headers: resHeaders,
            status: 200
          })
        }
        const cachePath = this._path
        // avoid opening cache file handles until a user actually tries to
        // read from it.
        const body = new Minipass()
        const fitInMemory = info.size < MAX_MEM_SIZE
        const removeOnResume = () => body.removeListener('resume', onResume)
        const onResume =
          opts.memoize !== false && fitInMemory
github npm / make-fetch-happen / cache.js View on Github external
}).then(info => {
      if (info && info.metadata && matchDetails(req, {
        url: info.metadata.url,
        reqHeaders: new fetch.Headers(info.metadata.reqHeaders),
        resHeaders: new fetch.Headers(info.metadata.resHeaders),
        cacheIntegrity: info.integrity,
        integrity: opts && opts.integrity
      })) {
        const resHeaders = new fetch.Headers(info.metadata.resHeaders)
        addCacheHeaders(resHeaders, this._path, key, info.integrity, info.time)
        if (req.method === 'HEAD') {
          return new fetch.Response(null, {
            url: req.url,
            headers: resHeaders,
            status: 200
          })
        }
        const cachePath = this._path
        // avoid opening cache file handles until a user actually tries to
        // read from it.
github npm / make-fetch-happen / cache.js View on Github external
}).then(info => {
      if (info && info.metadata && matchDetails(req, {
        url: info.metadata.url,
        reqHeaders: new fetch.Headers(info.metadata.reqHeaders),
        resHeaders: new fetch.Headers(info.metadata.resHeaders),
        cacheIntegrity: info.integrity,
        integrity: opts && opts.integrity
      })) {
        const resHeaders = new fetch.Headers(info.metadata.resHeaders)
        addCacheHeaders(resHeaders, this._path, key, info.integrity, info.time)
        if (req.method === 'HEAD') {
          return new fetch.Response(null, {
            url: req.url,
            headers: resHeaders,
            status: 200
          })
        }
        const cachePath = this._path
        // avoid opening cache file handles until a user actually tries to
        // read from it.
        const body = new Minipass()
github npm / make-fetch-happen / test / warning.js View on Github external
t.test('validate append headers', (t) => {
    const date = JSON.stringify(new Date().toUTCString())
    const replace = false

    const headers = new Fetch.Headers()
    const req = new Fetch.Request(url, { headers })

    const origHeaderAppend = req.headers.append

    req.headers.append = (...args) => {
      const expectedValue = `999 google.com {"hello":"world"} ${date}`

      t.equal('Warning', args[0])
      t.same(expectedValue, args[1])
      return origHeaderAppend.call(headers, ...args)
    }

    setWarning(req, code, message, replace)

    req.headers.append = origHeaderAppend
    t.end()
github npm / make-fetch-happen / index.js View on Github external
function remoteFetch (uri, opts) {
  const agent = getAgent(uri, opts)
  const headers = Object.assign({
    connection: agent ? 'keep-alive' : 'close',
    'user-agent': USER_AGENT
  }, opts.headers || {})

  const reqOpts = {
    agent,
    body: opts.body,
    compress: opts.compress,
    follow: opts.follow,
    headers: new fetch.Headers(headers),
    method: opts.method,
    redirect: 'manual',
    size: opts.size,
    counter: opts.counter,
    timeout: opts.timeout
  }

  return retry(
    (retryHandler, attemptNum) => {
      const req = new fetch.Request(uri, reqOpts)
      return fetch(req)
        .then((res) => {
          if (opts.integrity) {
            res = remoteFetchHandleIntegrity(res, opts.integrity)
          }

minipass-fetch

An implementation of window.fetch in Node.js using Minipass streams

MIT
Latest version published 3 months ago

Package Health Score

95 / 100
Full package analysis