Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Set User-Agent: HTTP header #907

Merged
merged 1 commit into from
Apr 29, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions scripts/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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.');
}
Expand Down