Skip to content

Commit

Permalink
fix: restore gateway redirect of HEAD requests
Browse files Browse the repository at this point in the history
preload requests require explicit opt-out hint
as noted in #505
  • Loading branch information
lidel committed Jun 27, 2018
1 parent 2bfda53 commit 910125e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
5 changes: 0 additions & 5 deletions add-on/src/lib/ipfs-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ function preNormalizationSkip (state, request) {

// types of requests to be skipped after expensive normalization happens
function postNormalizationSkip (state, request) {
// Ignore preload requests
if (request.method === 'HEAD') {
return true
}

// skip requests to the public gateway if embedded node is running (otherwise we have too much recursion)
if (state.ipfsNodeType === 'embedded' && request.url.startsWith(state.pubGwURLString)) {
return true
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 @@ -87,9 +87,9 @@ describe('modifyRequest', function () {
const request = url2request('https://google.com/ipfs/notacid?argTest#hashTest')
expect(modifyRequest(request)).to.equal(undefined)
})
it(`should be left untouched if its is a preload request (${nodeType} node)`, function () {
// HTTP HEAD is a legacy way for preloading data at arbitrary gateways - it should arrive at original destination
const headRequest = {url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', method: 'HEAD'}
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'}
expect(modifyRequest(headRequest)).to.equal(undefined)
})
})
Expand Down

0 comments on commit 910125e

Please sign in to comment.