PHP 8.2.30
Preview: fetch.js Size: 2.16 KB
/opt/alt/alt-nodejs9/root/lib/node_modules/npm/node_modules/npm-registry-client/lib/fetch.js

var assert = require('assert')
var url = require('url')

var request = require('request')
var once = require('once')

module.exports = fetch

function fetch (uri, params, cb) {
  assert(typeof uri === 'string', 'must pass uri to request')
  assert(params && typeof params === 'object', 'must pass params to request')
  assert(typeof cb === 'function', 'must pass callback to request')

  cb = once(cb)

  var client = this
  this.attempt(function (operation) {
    makeRequest.call(client, uri, params, function (er, req) {
      if (er) return cb(er)

      req.once('error', retryOnError)

      function retryOnError (er) {
        if (operation.retry(er)) {
          client.log.info('retry', 'will retry, error on last attempt: ' + er)
        } else {
          cb(er)
        }
      }

      req.on('response', function (res) {
        client.log.http('fetch', '' + res.statusCode, uri)
        req.removeListener('error', retryOnError)

        var er
        var statusCode = res && res.statusCode
        if (statusCode === 200) {
          res.resume()

          req.once('error', function (er) {
            res.emit('error', er)
          })

          return cb(null, res)
          // Only retry on 408, 5xx or no `response`.
        } else if (statusCode === 408) {
          er = new Error('request timed out')
        } else if (statusCode >= 500) {
          er = new Error('server error ' + statusCode)
        }

        if (er && operation.retry(er)) {
          client.log.info('retry', 'will retry, error on last attempt: ' + er)
        } else {
          cb(new Error('fetch failed with status code ' + statusCode))
        }
      })
    })
  })
}

function makeRequest (remote, params, cb) {
  var parsed = url.parse(remote)
  this.log.http('fetch', 'GET', parsed.href)

  var headers = params.headers || {}
  var er = this.authify(
    params.auth && params.auth.alwaysAuth,
    parsed,
    headers,
    params.auth
  )
  if (er) return cb(er)

  var opts = this.initialize(
    parsed,
    'GET',
    'application/x-tar, application/vnd.github+json; q=0.1',
    headers
  )
  // always want to follow redirects for fetch
  opts.followRedirect = true

  cb(null, request(opts))
}

Directory Contents

Dirs: 1 × Files: 20

Name Size Perms Modified Actions
dist-tags DIR
- drwxr-xr-x 2024-03-03 22:42:04
Edit Download
4.40 KB lrw-r--r-- 2021-09-28 11:28:11
Edit Download
3.81 KB lrw-r--r-- 2021-09-28 11:28:11
Edit Download
487 B lrw-r--r-- 2021-09-28 11:28:11
Edit Download
815 B lrw-r--r-- 2021-09-28 11:28:11
Edit Download
1.27 KB lrw-r--r-- 2021-09-28 11:28:11
Edit Download
2.16 KB lrw-r--r-- 2021-09-28 11:28:11
Edit Download
651 B lrw-r--r-- 2021-09-28 11:28:11
Edit Download
2.53 KB lrw-r--r-- 2021-09-28 11:28:11
Edit Download
722 B lrw-r--r-- 2021-09-28 11:28:11
Edit Download
1.75 KB lrw-r--r-- 2021-09-28 11:28:11
Edit Download
661 B lrw-r--r-- 2021-09-28 11:28:11
Edit Download
5.58 KB lrw-r--r-- 2021-09-28 11:28:11
Edit Download
9.42 KB lrw-r--r-- 2021-09-28 11:28:11
Edit Download
533 B lrw-r--r-- 2021-09-28 11:28:11
Edit Download
1.37 KB lrw-r--r-- 2021-09-28 11:28:11
Edit Download
651 B lrw-r--r-- 2021-09-28 11:28:11
Edit Download
690 B lrw-r--r-- 2021-09-28 11:28:11
Edit Download
2.89 KB lrw-r--r-- 2021-09-28 11:28:11
Edit Download
3.70 KB lrw-r--r-- 2021-09-28 11:28:11
Edit Download
665 B lrw-r--r-- 2021-09-28 11:28:11
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).