-
Notifications
You must be signed in to change notification settings - Fork 325
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
44c3a82
support for fs: URIs without redirecting to http:
the8472 6804106
tests pass locally, not on travis. let's see if this helps
the8472 18cb543
backup prefs once, restore from backup before tests
the8472 fb7fb15
protocol handlers emit http urls by default
the8472 20a53e2
pacify eslint
the8472 0b08570
canonical uris with private gateway enabled
the8472 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
language: node_js | ||
node_js: | ||
- "0.12" | ||
- "4.1" | ||
sudo: false | ||
addons: | ||
apt: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict' | ||
|
||
const {Ci} = require('chrome') | ||
const events = require('sdk/system/events') | ||
const gw = require('./gateways.js') | ||
|
||
/* | ||
const catman = Cc['@mozilla.org/categorymanager;1'].getService(CI.nsICategoryManager) | ||
// category ("net-channel-event-sinks") | ||
catman.addCategoryEntry(in string aCategory, in string aEntry, in string aValue, in boolean aPersist, in boolean aReplace) | ||
*/ | ||
|
||
function fixupRequest (e) { | ||
if (e.type !== 'http-on-modify-request') { | ||
return | ||
} | ||
if (!gw.fsUris) { | ||
return | ||
} | ||
const channel = e.subject.QueryInterface(Ci.nsIHttpChannel) | ||
|
||
channel.QueryInterface(Ci.nsIHttpChannelInternal) | ||
channel.QueryInterface(Ci.nsIPropertyBag2) | ||
channel.QueryInterface(Ci.nsIPropertyBag) | ||
|
||
let isIpfsReq = null | ||
try { | ||
isIpfsReq = channel.hasKey('ipfs-uri') | ||
} catch (e) { | ||
// console.log(e) | ||
} | ||
|
||
if (isIpfsReq && channel.originalURI.scheme === 'fs') { | ||
/* | ||
// TODO: investigate effects of the following flags | ||
// cookies make no sense in the ipfs context, we don't want to carry different gateway cookies into the page | ||
channel.loadFlags |= Ci.nsIRequest.LOAD_ANONYMOUS | ||
// should only do that for /ipfs/ paths since those are stable | ||
channel.loadFlags |= Ci.nsIRequest.VALIDATE_NEVER | ||
*/ | ||
|
||
// prevent redirects from replacing the effective URI | ||
channel.loadFlags &= ~Ci.nsIChannel.LOAD_REPLACE | ||
|
||
} | ||
|
||
} | ||
|
||
events.on('http-on-modify-request', fixupRequest) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,25 @@ | ||
'use strict' | ||
|
||
const { before, after } = require('sdk/test/utils') | ||
const { before } = require('sdk/test/utils') | ||
const { prefs } = require('sdk/simple-prefs') | ||
|
||
exports.storePrefs = (backup) => { | ||
// console.log('Backing up simple-prefs') | ||
if (!backup) { | ||
backup = new Map() | ||
} | ||
for (let key in prefs) { | ||
backup.set(key, prefs[key]) | ||
} | ||
return backup | ||
const backup = new Map() | ||
|
||
for (let key in prefs) { | ||
backup.set(key, prefs[key]) | ||
} | ||
|
||
exports.restorePrefs = (backup) => { | ||
function restorePrefs () { | ||
// console.log('Restoring simple-prefs') | ||
for (let [key, data] of backup) { | ||
prefs[key] = data | ||
} | ||
} | ||
|
||
exports.restorePrefs = restorePrefs | ||
|
||
exports.isolateTestCases = (testCases) => { | ||
let backup = null | ||
before(testCases, (name, assert) => { | ||
backup = exports.storePrefs() | ||
}) | ||
after(testCases, (name, assert) => { | ||
exports.restorePrefs(backup) | ||
restorePrefs() | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
'use strict' | ||
|
||
const tabs = require('sdk/tabs') | ||
const protocols = require('../lib/protocols.js') | ||
const fsFactory = protocols.fs | ||
|
||
protocols.register() | ||
|
||
const fs = fsFactory.createInstance() | ||
const gw = require('../lib/gateways.js') | ||
const self = require('sdk/self') | ||
const testpage = self.data.url('linkify-demo.html') | ||
const sripage = 'fs:/ipfs/QmSrCRJmzE4zE1nAfWPbzVfanKQNBhp7ZWmMnEdbiLvYNh/mdown#sample.md' | ||
const parent = require('sdk/remote/parent') | ||
|
||
const childMain = require.resolve('../lib/child-main.js') | ||
|
||
parent.remoteRequire(childMain) | ||
|
||
const {Cc, Ci} = require('chrome') | ||
const ioservice = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService) | ||
|
||
ioservice.newURI('fs:/ipns/foo', null, null) | ||
|
||
exports['test newURI'] = function (assert) { | ||
require('sdk/simple-prefs').prefs.fsUris = true | ||
|
||
assert.equal(fs.newURI('fs:/ipns/foo', null, null).spec, 'fs:/ipns/foo', 'keeps fs:/ uris as-is') | ||
} | ||
|
||
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', '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 | ||
exports['test subresource loading'] = function (assert, done) { | ||
require('sdk/simple-prefs').prefs.fsUris = true | ||
gw.redirectEnabled = false | ||
|
||
tabs.open({ | ||
url: testpage, | ||
onReady: (tab) => { | ||
|
||
// first load somehow doesn't have protocol handlers registered. so load resource:// first, then redirect to fs:/ page | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this is the same bug as in #33 (comment) |
||
if (tab.url !== sripage) { | ||
tab.url = sripage | ||
tab.reload() | ||
return | ||
} | ||
|
||
let worker = tab.attach({ | ||
contentScript: ` | ||
let obs = new MutationObserver(function(mutations) { | ||
let result = (document.querySelector("#ipfs-markdown-reader") instanceof HTMLHeadingElement) | ||
self.port.emit("test result", {result: result}) | ||
}) | ||
obs.observe(document.body,{childList: true}) | ||
` | ||
}) | ||
worker.port.on('test result', (msg) => { | ||
assert.equal(msg.result, true, 'subresource loaded successfully') | ||
|
||
require('sdk/simple-prefs').prefs.fsUris = false | ||
tab.close(done) | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
require('./prefs-util.js').isolateTestCases(exports) | ||
require('sdk/test').run(exports) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@the8472 I am going over the backlog and trying to have a better understanding of this part of code. I see this is related to protocols.js#L121-L131 but can't infer full picture from code alone.
Could you elaborate what is the purpose of this fixup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure if it's still necessary.
There were some cases with redirects coming from the server which needed the LOAD_REPLACE flag to be removed. If it is not removed the new channel's URI overrides originalURI which leads to a http URI in the address bar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While implementing #72 I did some cleanup in c75a05d.
I did not notice any regressions, but would appreciate if you took a second look, perhaps I missed something.