[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for fs: URIs without redirecting to http: #70

Merged
merged 6 commits into from
Feb 14, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
canonical uris with private gateway enabled
  • Loading branch information
the8472 committed Feb 14, 2016
commit 0b085707442b45333e8adef73aa1c3728d0622ba
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