From ed3eb37c4f4e2a6eb3e472d98629905cdd99a461 Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Tue, 23 Dec 2014 00:27:03 +0300 Subject: [PATCH] download packages using https Or, in general, the same protocol as the registry; this is what npm seem to be doing. See issue #166 for details. --- lib/local-storage.js | 16 +++++++++++++++- lib/storage.js | 11 +++++++++++ lib/up-storage.js | 8 -------- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/lib/local-storage.js b/lib/local-storage.js index 81508ca9d..5ae74ab21 100644 --- a/lib/local-storage.js +++ b/lib/local-storage.js @@ -152,10 +152,24 @@ Storage.prototype.update_versions = function(name, newdata, callback) { var filename = URL.parse(verdata.dist.tarball).pathname.replace(/^.*\//, '') // we do NOT overwrite any existing records if (data._distfiles[filename] == null) { - data._distfiles[filename] = { + var hash = data._distfiles[filename] = { url: verdata.dist.tarball, sha: verdata.dist.shasum, } + + if (verdata._sinopia_uplink) { + // if we got this information from a known registry, + // use the same protocol for the tarball + // + // see https://github.com/rlidwka/sinopia/issues/166 + var tarball_url = URL.parse(hash.url) + var uplink_url = URL.parse(self.config.uplinks[verdata._sinopia_uplink].url) + if (uplink_url.host === tarball_url.host) { + tarball_url.protocol = uplink_url.protocol + hash.registry = verdata._sinopia_uplink + hash.url = URL.format(tarball_url) + } + } } } } diff --git a/lib/storage.js b/lib/storage.js index 1193a1b73..d3b03f7bb 100644 --- a/lib/storage.js +++ b/lib/storage.js @@ -493,6 +493,17 @@ Storage.prototype._sync_package_with_uplinks = function(name, pkginfo, options, fetched: Date.now() } + for (var i in up_res.versions) { + // this won't be serialized to json, + // kinda like an ES6 Symbol + Object.defineProperty(up_res.versions[i], '_sinopia_uplink', { + value : up.upname, + enumerable : false, + configurable : false, + writable : true, + }) + } + try { Storage._merge_versions(pkginfo, up_res, self.config) } catch(err) { diff --git a/lib/up-storage.js b/lib/up-storage.js index 69f67c4f4..e434dd384 100644 --- a/lib/up-storage.js +++ b/lib/up-storage.js @@ -25,14 +25,6 @@ function Storage(config, mainconfig) { self.server_id = mainconfig.server_id self.url = URL.parse(self.config.url) - if (self.url.hostname === 'registry.npmjs.org') { - // npm registry is too slow working with ssl :( - /*if (self.config._autogenerated) { - // encrypt all the things! - self.url.protocol = 'https' - self.config.url = URL.format(self.url) - }*/ - } _setupProxy.call(self, self.url.hostname, config, mainconfig, self.url.protocol === 'https:')