diff --git a/lib/configuration.js b/lib/configuration.js index b91ac9758c58e736bc3bed941600589f8e2533a2..4fc6b246abdbfae87f3ea611ba06ab0ec8346dd3 100644 --- a/lib/configuration.js +++ b/lib/configuration.js @@ -110,9 +110,14 @@ g_configs.production = { // return a 503 if a compute process would take over 10s to complete max_compute_duration: 10, disable_primary_support: true + /* + , http_proxy: { + port: 3128, + host: "127.0.0.1" + } + */ }; - // local development configuration g_configs.local = { URL: 'http://127.0.0.1:10002', @@ -130,6 +135,12 @@ g_configs.local = { max_compute_processes: undefined, max_compute_duration: 10, disable_primary_support: false +/* + , http_proxy: { + port: 3128, + host: "127.0.0.1" + } +*/ }; // test environments are variations on local diff --git a/lib/primary.js b/lib/primary.js index 3ec678df4aa31319d48b69b8da632e66f71c74d0..cefa8edafc75d2f3a3621ea5f176b27740748b3f 100644 --- a/lib/primary.js +++ b/lib/primary.js @@ -40,6 +40,7 @@ const https = require('https'), +http = require('http'), logger = require('./logging.js').logger, urlparse = require('urlparse'), jwk = require('jwcrypto/jwk'), @@ -115,12 +116,7 @@ exports.checkSupport = function(domain, cb) { cb(null, cacheValue); } - // now we need to check to see if domain purports to being a primary for browserid - var req = https.get({ - host: domain, - path: WELL_KNOWN_URL, - agent: false - }, function (res) { + function handleResponse(res) { if (res.statusCode !== 200) { logger.debug(domain + ' is not a browserid primary - non-200 response code to ' + WELL_KNOWN_URL); return cacheAndReturn(false); @@ -142,7 +138,30 @@ exports.checkSupport = function(domain, cb) { return cacheAndReturn(false); } }); - }).on('error', function(e) { + }; + + // now we need to check to see if domain purports to being a primary for browserid + var httpProxy = config.get('http_proxy'); + + var req; + if (httpProxy && httpProxy.port && httpProxy.host) { + req = http.get({ + host: httpProxy.host, + port: httpProxy.port, + path: 'https://' + domain + WELL_KNOWN_URL, + headers: { + host: domain + } + }, handleResponse); + } else { + req = https.get({ + host: domain, + path: WELL_KNOWN_URL, + agent: false + }, handleResponse); + } + + req.on('error', function(e) { logger.debug(domain + ' is not a browserid primary: ' + e.toString()); cacheAndReturn(false); }); @@ -174,7 +193,7 @@ if (process.env['SHIMMED_PRIMARIES']) { publicKey: r.publicKey }; - console.log("inserted primary info for '" + domain + "' into cache, pointed at '" + origin + "'"); + winston.info("inserted primary info for '" + domain + "' into cache, pointed at '" + origin + "'"); }); } diff --git a/scripts/check_primary_support b/scripts/check_primary_support index 51044ed38338050b93cfc84dcaa7cd7f2d1e959a..ef913d3bdb493af6c43f748ff1af2516b9608f9b 100755 --- a/scripts/check_primary_support +++ b/scripts/check_primary_support @@ -1,11 +1,11 @@ +#!/usr/bin/env node + /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#!/usr/bin/env node - const -primary = require('../lib/browserid/primary'), +primary = require('../lib/primary'), logging = require('../lib/logging.js'); logging.enableConsoleLogging();