Skip to content

Commit

Permalink
use exported vars
Browse files Browse the repository at this point in the history
  • Loading branch information
the8472 committed Dec 15, 2015
1 parent 236b680 commit fda78c3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/gateways.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ var prefs = require('sdk/simple-prefs').prefs;
var ioservice = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService);

const IPFS_RESOURCE = /^https?:\/\/[^\/]+\/ip(f|n)s\//;

exports.IPFS_RESOURCE = IPFS_RESOURCE;

var PUBLIC_GATEWAY_HOSTS; // getPublicGatewayHostsRegex()
var PUBLIC_GATEWAY_URI; // getDefaultPublicURI();
var CUSTOM_GATEWAY_URI;
Expand Down Expand Up @@ -73,3 +76,6 @@ exports.customUri = function() {
exports.publicUri = function() {
return PUBLIC_GATEWAY_URI;
};
exports.publicHosts = function() {
return PUBLIC_GATEWAY_HOSTS;
};
4 changes: 2 additions & 2 deletions lib/redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ var ipfsRequestObserver = {
if (topic == 'http-on-modify-request') {
let channel = subject.QueryInterface(Ci.nsIHttpChannel);
let httpUrl = channel.URI.spec;
if (httpUrl.match(PUBLIC_GATEWAY_HOSTS) && httpUrl.match(IPFS_RESOURCE)) {
if (httpUrl.match(gw.publicHosts()) && httpUrl.match(gw.IPFS_RESOURCE)) {
channel.setRequestHeader('x-ipfs-firefox-addon', 'true', false);
if (prefs.useCustomGateway) {
//console.info('Detected HTTP request to the public gateway: ' + channel.URI.spec);
let uri = ioservice.newURI(httpUrl.replace(PUBLIC_GATEWAY_HOSTS, CUSTOM_GATEWAY_URI.spec), null, null);
let uri = ioservice.newURI(httpUrl.replace(gw.publicHosts(), customUri().spec), null, null);
//console.info('Redirecting to custom gateway: ' + uri.spec);
channel.redirectTo(uri);
}
Expand Down

0 comments on commit fda78c3

Please sign in to comment.