[go: nahoru, domu]

Skip to content

Commit

Permalink
canonical uris with private gateway enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
the8472 committed Feb 14, 2016
1 parent 20a53e2 commit 0b08570
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions lib/gateways.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ Object.defineProperty(exports, 'publicUri', {
}
})

Object.defineProperty(exports, 'gwUri', {
get: function () {
return this.redirectEnabled ? CUSTOM_GATEWAY_URI : PUBLIC_GATEWAY_URI
}
})

Object.defineProperty(exports, 'publicHosts', {
get: function () {
return PUBLIC_GATEWAY_HOSTS
Expand Down
3 changes: 1 addition & 2 deletions lib/protocols.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ CommonProtocolHandler.prototype = Object.freeze({
newChannel2: function (aURI, loadInfo) {
// console.info('Detected newChannel for IPFS protocol: ' + aURI.spec)
let normalized = this.normalizedIpfsPath(this.pathPrefix + aURI.path)
let gwUri = gw.publicUri
let httpUri = ioservice.newURI(normalized, aURI.originCharset, gwUri)
let httpUri = ioservice.newURI(normalized, aURI.originCharset, gw.gwUri)
let channel = null

if (loadInfo !== null) {
Expand Down
9 changes: 8 additions & 1 deletion test/test-canonical-fs-uris.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,21 @@ exports['test newURI'] = function (assert) {

exports['test newChannel'] = function (assert) {
require('sdk/simple-prefs').prefs.fsUris = true
gw.redirectEnabled = false

let uri = fs.newURI('fs:///ipns/foo', null, null)
let chan = fs.newChannel(uri)

assert.equal(chan.originalURI.spec, 'fs:/ipns/foo', "keeps fs: URI as channel's originalURI")

// double and triple slashes lead to gateway redirects, which cause CORS troubles -> check normalization
assert.equal(chan.URI.spec, 'https://ipfs.io/ipns/foo', 'channel has normalized http urls')
assert.equal(chan.URI.spec, 'https://ipfs.io/ipns/foo', 'redirect off, channel has normalized http urls')

gw.redirectEnabled = true

chan = fs.newChannel(uri)

assert.equal(chan.URI.spec, 'http://127.0.0.1:8080/ipns/foo', 'redirect on, channel has normalized http urls')
}

// https://github.com/lidel/ipfs-firefox-addon/issues/3
Expand Down

0 comments on commit 0b08570

Please sign in to comment.