diff --git a/add-on/src/lib/ipfs-request.js b/add-on/src/lib/ipfs-request.js index 0626d1393..28551f8aa 100644 --- a/add-on/src/lib/ipfs-request.js +++ b/add-on/src/lib/ipfs-request.js @@ -66,7 +66,7 @@ function createRequestModifier (getState, dnslinkResolver, ipfsPathValidator, ru ignore(request.requestId) } // skip if a per-site redirect opt-out exists - const parentUrl = request.originUrl || request.initiator // FF: originUrl, Chrome: initiator + const parentUrl = request.originUrl || request.initiator // FF: originUrl (Referer-like Origin URL), Chrome: initiator (just Origin) const fqdn = new URL(request.url).hostname const parentFqdn = parentUrl && request.url !== parentUrl ? new URL(parentUrl).hostname : null if (state.noRedirectHostnames.some(optout => @@ -76,9 +76,9 @@ function createRequestModifier (getState, dnslinkResolver, ipfsPathValidator, ru } // additional checks limited to requests for root documents if (request.type === 'main_frame') { - // trigger DNSLink lookup if status for root domain is not in cache yet + // lazily trigger DNSLink lookup (will do anything only if status for root domain is not in cache) if (state.dnslinkPolicy && dnslinkResolver.canLookupURL(request.url)) { - (async () => dnslinkResolver.readAndCacheDnslink(parentFqdn || fqdn))() + dnslinkResolver.preloadDnslink(request.url) } } return isIgnored(request.requestId) diff --git a/test/functional/lib/ipfs-request-dnslink.test.js b/test/functional/lib/ipfs-request-dnslink.test.js index 30faf4f7f..35a15ba15 100644 --- a/test/functional/lib/ipfs-request-dnslink.test.js +++ b/test/functional/lib/ipfs-request-dnslink.test.js @@ -219,7 +219,7 @@ describe('modifyRequest processing', function () { // force-clear dnslink cache to enable cache miss dnslinkResolver.clearCache() }) - it('should redirect in onHeadersReceived if DNS TXT record exists and x-ipfs-path header is present', function () { + it('should redirect subrequests in onHeadersReceived if DNS TXT record exists and x-ipfs-path header is present', function () { // clear dnslink cache to ensure miss dnslinkResolver.clearCache() // stub existence of a valid DNS record @@ -227,6 +227,7 @@ describe('modifyRequest processing', function () { dnslinkResolver.readDnslinkFromTxtRecord = sinon.stub().withArgs(fqdn).returns('/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd') // const request = url2request('http://explore.ipld.io/index.html?argTest#hashTest') + request.type = 'sub_frame' // we test a subrequests because main_frame gets early DNSLink preload in onBeforeRequest expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined) // simulate presence of x-ipfs-path header returned by HTTP gateway request.responseHeaders = [{ name: 'X-Ipfs-Path', value: '/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd' }] @@ -241,6 +242,7 @@ describe('modifyRequest processing', function () { dnslinkResolver.readDnslinkFromTxtRecord = sinon.stub().withArgs(fqdn).returns(false) // const request = url2request('http://explore.ipld.io/index.html?argTest#hashTest') + request.type = 'sub_frame' // we test a subrequest here because main_frame gets early DNSLink preload in onBeforeRequest expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined) // simulate presence of x-ipfs-path header returned by HTTP gateway request.responseHeaders = [{ name: 'X-Ipfs-Path', value: '/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd' }] @@ -255,6 +257,7 @@ describe('modifyRequest processing', function () { dnslinkResolver.readDnslinkFromTxtRecord = sinon.stub().withArgs(fqdn).returns('/ipfs/QmbfimSwTuCvGL8XBr3yk1iCjqgk2co2n21cWmcQohymDd') // const request = url2request('http://explore.ipld.io/index.html?argTest#hashTest') + request.type = 'sub_frame' // we test a subrequest here because main_frame gets early DNSLink preload in onBeforeRequest expect(modifyRequest.onBeforeRequest(request)).to.equal(undefined) expect(modifyRequest.onHeadersReceived(request)).to.equal(undefined) })