From fa74e51102c2111f1fe05b05cb232d6d47bb80ff Mon Sep 17 00:00:00 2001 From: David Glasser Date: Tue, 3 Mar 2015 16:04:28 -0800 Subject: [PATCH] Add direct access to `request` module from http --- packages/http/httpcall_server.js | 9 +++++++++ packages/http/httpcall_tests.js | 7 +++++++ packages/http/package.js | 2 ++ 3 files changed, 18 insertions(+) diff --git a/packages/http/httpcall_server.js b/packages/http/httpcall_server.js index 80a051b41e..acfe8067ad 100644 --- a/packages/http/httpcall_server.js +++ b/packages/http/httpcall_server.js @@ -2,6 +2,15 @@ var path = Npm.require('path'); var request = Npm.require('request'); var url_util = Npm.require('url'); +HTTPInternals = { + NpmModules: { + request: { + version: Npm.require('request/package.json').version, + module: request + } + } +}; + // _call always runs asynchronously; HTTP.call, defined below, // wraps _call and runs synchronously when no callback is provided. var _call = function(method, url, options, callback) { diff --git a/packages/http/httpcall_tests.js b/packages/http/httpcall_tests.js index c5db6e84d1..92c24ae365 100644 --- a/packages/http/httpcall_tests.js +++ b/packages/http/httpcall_tests.js @@ -490,6 +490,13 @@ if (Meteor.isServer) { ]); } +Meteor.isServer && Tinytest.add("httpcall - npm modules", function (test) { + // Make sure the version number looks like a version number. (All published + // request version numbers end in ".0".) + test.matches(HTTPInternals.NpmModules.request.version, /^2\.(\d+)\.0/); + test.equal(typeof(HTTPInternals.NpmModules.request.module), 'function'); + test.isTrue(HTTPInternals.NpmModules.request.module.get); +}); // TO TEST/ADD: // - https diff --git a/packages/http/package.js b/packages/http/package.js index 8079db8c4e..74228aff30 100644 --- a/packages/http/package.js +++ b/packages/http/package.js @@ -9,6 +9,7 @@ Package.onUse(function (api) { api.use('underscore'); api.use('url'); api.export('HTTP'); + api.export('HTTPInternals', 'server'); api.addFiles('httpcall_common.js', ['client', 'server']); api.addFiles('httpcall_client.js', 'client'); api.addFiles('httpcall_server.js', 'server'); @@ -21,6 +22,7 @@ Package.onTest(function (api) { api.use('random'); api.use('jquery', 'client'); api.use('http', ['client', 'server']); + api.use('tinytest'); api.use('test-helpers', ['client', 'server']); api.addFiles('test_responder.js', 'server');