From 8ef71228116a09788c254e6c0032a94bb1453ac7 Mon Sep 17 00:00:00 2001 From: Romein van Buren Date: Fri, 15 Jul 2022 17:28:30 +0200 Subject: [PATCH] Force requests over IPv4 --- lib/testendpoints.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/testendpoints.js b/lib/testendpoints.js index 4cf6961..2b13f6e 100644 --- a/lib/testendpoints.js +++ b/lib/testendpoints.js @@ -3,6 +3,12 @@ const fetch = require('node-fetch'); const { operators } = require('./operators'); const { realValues } = require('./realvalues'); +const http = require('http'); +const https = require('https'); + +// Force requests over IPv4 +const httpAgent = new http.Agent({ family: 4 }); +const httpsAgent = new https.Agent({ family: 4 }); async function testEndpoints(endpoints) { const output = { @@ -20,7 +26,15 @@ async function testEndpoints(endpoints) { return obj; }, {}); - const res = await fetch(endpoint.uri, { headers }); + const res = await fetch(endpoint.uri, { + headers, + agent: url => { + if (url.protocol === 'http:') { + return httpAgent; + } + return httpsAgent; + }, + }); const body = await res.text(); endpoint.requirements.forEach(requirement => {