-
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 1 commit
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
Next
Next commit
support for fs: URIs without redirecting to http:
fixes #48
- Loading branch information
commit 44c3a826b671b6e2fbc660aba778f2301a0cdbd2
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
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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
'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 | ||
|
||
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') | ||
} | ||
|
||
// 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
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.