Skip to content

Commit

Permalink
Redirect ipfs: protocol using real HTTP gateway URI
Browse files Browse the repository at this point in the history
closes #7, closes #3
  • Loading branch information
lidel committed Mar 25, 2015
1 parent 1d04228 commit 9ca515a
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,24 @@ IpfsProtocolHandler.prototype = Object.freeze({
},

protocolFlags: Ci.nsIProtocolHandler.URI_NOAUTH |
Ci.nsIProtocolHandler.ALLOWS_PROXY_HTTP |
Ci.nsIProtocolHandler.URI_LOADABLE_BY_ANYONE,

newURI: function(aSpec, aOriginCharset, aBaseURI) {
// presence of aBaseURI means a dependent resource or a relative link
// and we need to return correct http URI
if (aBaseURI && aBaseURI.scheme == IPFS_SCHEME) {
//console.log('newURI/aSpec: ' + aSpec);
//console.log('newURI/aBaseURI.spec: ' + aBaseURI.spec);
if (aBaseURI && aBaseURI.scheme == this.scheme) {
let httpBaseURI = ioservice.newURI(PUBLIC_GATEWAY_URI.spec + aBaseURI.path, null, null);
//console.log('newURI/httpBaseURI.spec: ' + httpBaseURI.spec);
let newURI = ioservice.newURI(aSpec, aOriginCharset, httpBaseURI);
//console.log('newURI/newURI.spec: ' + newURI.spec);
return newURI;
}
/* Left for future use (if we enable channel.originalURI in newChannel method)
let uri = Cc['@mozilla.org/network/simple-uri;1'].createInstance(Ci.nsIURI);
uri.spec = aSpec;
//uri.spec = (aBaseURI === null) ? aSpec : PUBLIC_GATEWAY_URI.resolve(aSpec);
return uri;
*/
let ipfsPath = aSpec.replace(/^ipfs:/,'');
let newURI = ioservice.newURI(PUBLIC_GATEWAY_URI.spec + ipfsPath, aOriginCharset, null);
return newURI;
},

newChannel: function(aURI) {
Expand All @@ -90,7 +89,6 @@ IpfsProtocolHandler.prototype = Object.freeze({
if (aOuter) {
throw Cr.NS_ERROR_NO_AGGREGATION;
}
//return (new IpfsProtocolHandler()).QueryInterface(aIID);
return new IpfsProtocolHandler();
},
register: function() {
Expand Down

0 comments on commit 9ca515a

Please sign in to comment.