Skip to content

Commit

Permalink
refactor: rename opt-out symbol to x-ipfs-companion-no-redirect
Browse files Browse the repository at this point in the history
As suggested in
#505 (comment)
  • Loading branch information
lidel committed Jul 2, 2018
1 parent 35f68cc commit 88325d1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ If tested path is a valid IPFS address it gets redirected and loaded from a loca
It is possible to opt-out from redirect by
a) suspending extension via global toggle
b) including `x-ipfs-no-redirect` in the URL ([as a hash or query parameter](https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?x-ipfs-no-redirect#x-ipfs-no-redirect)).
b) including `x-ipfs-companion-no-redirect` in the URL ([as a hash or query parameter](https://ipfs.io/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?x-ipfs-companion-no-redirect#x-ipfs-companion-no-redirect)).

#### IPFS API as `window.ipfs`

Expand Down
4 changes: 2 additions & 2 deletions add-on/src/lib/ipfs-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

const IsIpfs = require('is-ipfs')
const { urlAtPublicGw } = require('./ipfs-path')
const redirectOptOutHint = 'x-ipfs-no-redirect'
const redirectOptOutHint = 'x-ipfs-companion-no-redirect'

function createRequestModifier (getState, dnsLink, ipfsPathValidator, runtime) {
// Request modifier provides event listeners for the various stages of making an HTTP request
Expand Down Expand Up @@ -136,7 +136,7 @@ function redirectToGateway (requestUrl, state) {

function isSafeToRedirect (request, runtime) {
// Do not redirect if URL includes opt-out hint
if (request.url.includes('x-ipfs-no-redirect')) {
if (request.url.includes('x-ipfs-companion-no-redirect')) {
return false
}

Expand Down
6 changes: 3 additions & 3 deletions test/functional/lib/ipfs-request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ describe('modifyRequest.onBeforeRequest', function () {
})
it(`should be left untouched if URL includes opt-out hint (${nodeType} node)`, function () {
// A safe way for preloading data at arbitrary gateways - it should arrive at original destination
const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?x-ipfs-no-redirect#hashTest')
const request = url2request('https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?x-ipfs-companion-no-redirect#hashTest')
expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined)
expect(redirectOptOutHint).to.equal('x-ipfs-no-redirect')
expect(redirectOptOutHint).to.equal('x-ipfs-companion-no-redirect')
})
it(`should be left untouched if CID is invalid (${nodeType} node)`, function () {
const request = url2request('https://google.com/ipfs/notacid?argTest#hashTest')
expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined)
})
it(`should be left untouched if its is a HEAD preload with explicit opt-out in URL hash (${nodeType} node)`, function () {
// HTTP HEAD is a popular way for preloading data at arbitrary gateways, so we have a dedicated test to make sure it works as expected
const headRequest = {url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#x-ipfs-no-redirect', method: 'HEAD'}
const headRequest = {url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#x-ipfs-companion-no-redirect', method: 'HEAD'}
expect(modifyRequest.onBeforeRequest(headRequest)).to.equal(undefined)
})
})
Expand Down

0 comments on commit 88325d1

Please sign in to comment.