Skip to content

Commit

Permalink
fix: do not redirect preload requests
Browse files Browse the repository at this point in the history
HTTP HEAD is often used for preloading data at arbitrary gateways.
It should arrive at original destination, no matter what hostname is
used.
  • Loading branch information
lidel committed Jun 4, 2018
1 parent 231df22 commit 1492d8d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion add-on/src/lib/ipfs-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function createRequestModifier (getState, dnsLink, ipfsPathValidator) {
// handle redirects to custom gateway
if (state.redirect) {
// Ignore preload requests
if (request.method === 'HEAD' && state.preloadAtPublicGateway && request.url.startsWith(state.pubGwURLString)) {
if (request.method === 'HEAD') {
return
}
// Ignore XHR requests for which redirect would fail due to CORS bug in Firefox
Expand Down
5 changes: 5 additions & 0 deletions test/functional/lib/ipfs-request.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ 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 often used for preloading data at arbitrary gateways - it should arrive at original destination
const headRequest = {url: 'https://google.com/ipfs/QmbWqxBEKC3P8tqsKc98xmWNzrzDtRLMiMPL8wBuTGsMnR?argTest#hashTest', method: 'HEAD'}
expect(modifyRequest(headRequest)).to.equal(undefined)
})
})
})
})
Expand Down

0 comments on commit 1492d8d

Please sign in to comment.