"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/lib/request.js" (8 Mar 2017, 3159 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 (function() {
    2   var config, configureRequest, loadNpm, npm, request;
    3 
    4   npm = require('npm');
    5 
    6   request = require('request');
    7 
    8   config = require('./apm');
    9 
   10   loadNpm = function(callback) {
   11     var npmOptions;
   12     npmOptions = {
   13       userconfig: config.getUserConfigPath(),
   14       globalconfig: config.getGlobalConfigPath()
   15     };
   16     return npm.load(npmOptions, callback);
   17   };
   18 
   19   configureRequest = function(requestOptions, callback) {
   20     return loadNpm(function() {
   21       var base, ref, userAgent;
   22       if (requestOptions.proxy == null) {
   23         requestOptions.proxy = npm.config.get('https-proxy') || npm.config.get('proxy') || process.env.HTTPS_PROXY || process.env.HTTP_PROXY;
   24       }
   25       if (requestOptions.strictSSL == null) {
   26         requestOptions.strictSSL = npm.config.get('strict-ssl');
   27       }
   28       userAgent = (ref = npm.config.get('user-agent')) != null ? ref : "AtomApm/" + (require('../package.json').version);
   29       if (requestOptions.headers == null) {
   30         requestOptions.headers = {};
   31       }
   32       if ((base = requestOptions.headers)['User-Agent'] == null) {
   33         base['User-Agent'] = userAgent;
   34       }
   35       return callback();
   36     });
   37   };
   38 
   39   module.exports = {
   40     get: function(requestOptions, callback) {
   41       return configureRequest(requestOptions, function() {
   42         var ref, requestsMade, retryCount, tryRequest;
   43         retryCount = (ref = requestOptions.retries) != null ? ref : 0;
   44         requestsMade = 0;
   45         tryRequest = function() {
   46           requestsMade++;
   47           return request.get(requestOptions, function(error, response, body) {
   48             var ref1;
   49             if (retryCount > 0 && ((ref1 = error != null ? error.code : void 0) === 'ETIMEDOUT' || ref1 === 'ECONNRESET')) {
   50               retryCount--;
   51               return tryRequest();
   52             } else {
   53               if ((error != null ? error.message : void 0) && requestsMade > 1) {
   54                 error.message += " (" + requestsMade + " attempts)";
   55               }
   56               return callback(error, response, body);
   57             }
   58           });
   59         };
   60         return tryRequest();
   61       });
   62     },
   63     del: function(requestOptions, callback) {
   64       return configureRequest(requestOptions, function() {
   65         return request.del(requestOptions, callback);
   66       });
   67     },
   68     post: function(requestOptions, callback) {
   69       return configureRequest(requestOptions, function() {
   70         return request.post(requestOptions, callback);
   71       });
   72     },
   73     createReadStream: function(requestOptions, callback) {
   74       return configureRequest(requestOptions, function() {
   75         return callback(request.get(requestOptions));
   76       });
   77     },
   78     getErrorMessage: function(response, body) {
   79       var ref, ref1;
   80       if ((response != null ? response.statusCode : void 0) === 503) {
   81         return 'atom.io is temporarily unavailable, please try again later.';
   82       } else {
   83         return (ref = (ref1 = body != null ? body.message : void 0) != null ? ref1 : body != null ? body.error : void 0) != null ? ref : body;
   84       }
   85     },
   86     debug: function(debug) {
   87       return request.debug = debug;
   88     }
   89   };
   90 
   91 }).call(this);