Server IP : 127.0.0.2 / Your IP : 18.117.227.191 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/share/npm/node_modules/npm-registry-client/lib/ |
Upload File : |
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.on('error', function (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) var er var statusCode = res && res.statusCode if (statusCode === 200) { // Work around bug in node v0.10.0 where the CryptoStream // gets stuck and never starts reading again. res.resume() if (process.version === 'v0.10.0') unstick(res) 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 unstick (response) { response.resume = (function (orig) { return function () { var ret = orig.apply(response, arguments) if (response.socket.encrypted) response.socket.encrypted.read(0) return ret } })(response.resume) } 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)) }