Skip to content

Commit

Permalink
Include environment info in every web request.
Browse files Browse the repository at this point in the history
Pass available environment info (Meteor version, OS, etc) in every web
request in User-Agent http header. OS platfrom, release, arch, type
available from node api and Meteor release number.
  • Loading branch information
Vyacheslav Kim authored and Slava committed May 9, 2013
1 parent 5b2240d commit 0893b82
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
38 changes: 38 additions & 0 deletions tools/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

var fs = require("fs");
var path = require('path');
var os = require('os');
var util = require('util');
var _ = require('underscore');
var zlib = require("zlib");
var tar = require("tar");
Expand Down Expand Up @@ -485,6 +487,42 @@ _.extend(exports, {
var future = new Future;
// can't just use Future.wrap, because we want to return "body", not
// "response".

urlOrOptions = _.clone(urlOrOptions); // we are going to change it
var appVersion;
try {
appVersion = getToolsVersion();
} catch(e) {
appVersion = 'checkout';
}

// meteorReleaseContext - an option with information about app directory
// release versions, etc, is used to get exact Meteor version used.
if (urlOrOptions.hasOwnProperty('meteorReleaseContext')) {
// Get meteor app release version: if specified in command line args, take
// releaseVersion, if not specified, try global meteor version
var meteorReleaseContext = urlOrOptions.meteorReleaseContext;
appVersion = meteorReleaseContext.releaseVersion;

if (appVersion === 'none')
appVersion = meteorReleaseContext.appReleaseVersion;
if (appVersion === 'none')
appVersion = 'checkout';

delete urlOrOptions.meteorReleaseContext;
}

// Get some kind of User Agent: environment information.
var ua = util.format('Meteor/%s OS/%s (%s; %s; %s;)',
appVersion, os.platform(), os.type(), os.release(), os.arch());

var headers = {'User-Agent': ua };

if (_.isObject(urlOrOptions))
urlOrOptions.headers = _.extend(headers, urlOrOptions.headers);
else
urlOrOptions = { url: urlOrOptions, headers: headers };

request(urlOrOptions, function (error, response, body) {
if (error)
future.throw(new files.OfflineError(error));
Expand Down
11 changes: 8 additions & 3 deletions tools/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ var manifestUrl = testingUpdater
* Downloads the current manifest file and returns it via a callback (or
* null on error)
*/
exports.getManifest = function () {
return files.getUrl({url: manifestUrl, json: true});
exports.getManifest = function (context) {
var options = {url: manifestUrl, json: true};

if (context)
options.meteorReleaseContext = context;

return files.getUrl(options);
};

exports.startUpdateChecks = function (context) {
var updateCheck = inFiber(function () {
var manifest = null;
try {
manifest = exports.getManifest();
manifest = exports.getManifest(context);
} catch (e) {
// Ignore error (eg, offline), but still do the "can we update this app
// with a locally available release" check.
Expand Down

0 comments on commit 0893b82

Please sign in to comment.