From 35a1cb7b69b0427b4f022788a51a7155ab0094f4 Mon Sep 17 00:00:00 2001 From: Francois Daoust Date: Tue, 24 Nov 2026 08:42:16 +0100 Subject: [PATCH 1/2] Log Cf-Ray header if present when fetch fails Cloudflare adds a `Cf-Ray` header to HTTP responses that can be useful for debugging purpose when exchanging with server maintainers when a request gets rejected for some reason (for example, requests sent to registry.khronos.org are currently rejected by the server when the crawler runs in a GitHub workflow). This logs the date and the `Cf-Ray` in the error message. --- src/lib/util.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/lib/util.js b/src/lib/util.js index 0e02a270..492c497c 100644 --- a/src/lib/util.js +++ b/src/lib/util.js @@ -454,10 +454,14 @@ async function processSpecification(spec, processFunction, args, options) { } try { - // Fetch the spec URL if using https - // This allow to skip launching a browser - // if we have a fallback data source - // with a defined cache target for the spec + // Fetch the spec URL if using https. + // This allow to skip launching a browser if we have a fallback data + // source with a defined cache target for the spec. + // Note: Many servers are behind a CDN. Cloudflare adds a "Cf-Ray" + // header with a hashed value that encodes information about the data + // center and the visitor's request. We'll log that value along with + // the date in case of error as this is useful info to exchange with + // server maintainers when the crawler gets blocked for some reason. if (!spec.url.startsWith('file://')) { let response; // We set a conditional request header @@ -483,7 +487,9 @@ async function processSpecification(spec, processFunction, args, options) { throw new Error(`Loading ${spec.url} triggered network error`, { cause: err }); } if (response.status !== 200) { - throw new Error(`Loading ${spec.url} triggered HTTP status ${response.status}`); + const resInfo = response.headers.get('date') + + (response.headers.get('cf-ray') ? `, Cf-Ray: ${response.headers.get('cf-ray')}` : '') + throw new Error(`Loading ${spec.url} triggered HTTP status ${response.status} (${resInfo})`); } } const page = await browser.newPage(); @@ -538,13 +544,15 @@ async function processSpecification(spec, processFunction, args, options) { } catch (err) { throw new Error(`Loading ${spec.url} triggered network error`, { cause: err }); } + const responseHeaders = result.headers(); if ((result.status() !== 200) && (!spec.url.startsWith('file://') || (result.status() !== 0))) { - throw new Error(`Loading ${spec.url} triggered HTTP status ${result.status()}`); + const resInfo = responseHeaders['date'] + + (responseHeaders['cf-ray'] ? `, Cf-Ray: ${responseHeaders['cf-ray']}` : ''); + throw new Error(`Loading ${spec.url} triggered HTTP status ${result.status()} (${resInfo})`); } - const responseHeaders = result.headers(); // Use Last-Modified in preference as it is in practice // more reliable for conditional requests - if (responseHeaders['last-modified']) { + if (responseHeaders['last-modified']) { cacheInfo = {lastModified: responseHeaders['last-modified']}; } else if (responseHeaders.etag) { cacheInfo = {etag: responseHeaders.etag}; @@ -568,7 +576,9 @@ async function processSpecification(spec, processFunction, args, options) { // (Note HTTP status is 0 when `file://` URLs are loaded) const subresult = await subPage.goto(url, loadOptions); if ((subresult.status() !== 200) && (!url.startsWith('file://') || (subresult.status() !== 0))) { - throw new Error(`Loading ${spec.url} triggered HTTP status ${subresult.status()} when loading ${url}`); + const resInfo = subresult.headers()['date'] + + (subresult.headers()['cf-ray'] ? `, Cf-Ray: ${subresult.headers()['cf-ray']}` : ''); + throw new Error(`Loading ${spec.url} triggered HTTP status ${subresult.status()} (${resInfo}) when loading ${url}`); } const html = await subPage.evaluate(() => { return document.body.outerHTML From ba3583f2c42a38d9801729a4d1adbabe250d6f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Daoust?= Date: Tue, 24 Nov 2026 14:25:29 +0100 Subject: [PATCH 2/2] Update src/lib/util.js Co-authored-by: Denis Ah-Kang <1696128+deniak@users.noreply.github.com> --- src/lib/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/util.js b/src/lib/util.js index 492c497c..159f9c34 100644 --- a/src/lib/util.js +++ b/src/lib/util.js @@ -488,7 +488,7 @@ async function processSpecification(spec, processFunction, args, options) { } if (response.status !== 200) { const resInfo = response.headers.get('date') + - (response.headers.get('cf-ray') ? `, Cf-Ray: ${response.headers.get('cf-ray')}` : '') + (response.headers.get('cf-ray') ? `, Cf-Ray: ${response.headers.get('cf-ray')}` : ''); throw new Error(`Loading ${spec.url} triggered HTTP status ${response.status} (${resInfo})`); } }