From 1fd8d1402a95ce9a326e8ecea8b266779de17a39 Mon Sep 17 00:00:00 2001 From: Marcin Cieslak Date: Sat, 4 Apr 2015 20:46:03 +0000 Subject: [PATCH] Set User-Agent: HTTP header --- scripts/install.js | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/scripts/install.js b/scripts/install.js index 0c2052304..17ecf069e 100644 --- a/scripts/install.js +++ b/scripts/install.js @@ -6,7 +6,8 @@ var fs = require('fs'), mkdir = require('mkdirp'), npmconf = require('npmconf'), path = require('path'), - request = require('request'); + request = require('request'), + package = require('../package.json'); require('../lib/extensions'); @@ -21,21 +22,28 @@ require('../lib/extensions'); function download(url, dest, cb) { var returnError = function(err) { - cb(typeof err.message === 'string' ? err.message : err); + cb(typeof err.message === 'string' ? err.message : err); }; + if (url) { - applyProxy({ rejectUnauthorized: false }, function(options) { - request.get(url, options).on('response', function(response) { - if (response.statusCode < 200 || response.statusCode >= 300) { - returnError(['Can not download file from:', url].join()); - return; - } - - response.pipe(fs.createWriteStream(dest)); - - cb(); - }).on('error', returnError); - }); + applyProxy({ rejectUnauthorized: false }, function(options) { + options.headers = { + 'User-Agent': [ + 'node/', process.version, ' ', + 'node-sass-installer/', package.version + ].join('') + }; + request.get(url, options).on('response', function(response) { + if (response.statusCode < 200 || response.statusCode >= 300) { + returnError(['Can not download file from:', url].join()); + return; + } + + response.pipe(fs.createWriteStream(dest)); + + cb(); + }).on('error', returnError); + }); } else { returnError('Download URL not defined, set SASS_BINARY_SITE in the environment to enable download.'); }