From 9eee5ca5eed64ef7926c677455ad35b19f5d4215 Mon Sep 17 00:00:00 2001 From: Matt Reale Date: Fri, 3 Nov 2023 14:40:39 -0400 Subject: [PATCH] Adding support for relative urls Improving redirect logic to follow relative urls --- lib/check-status-code.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/check-status-code.js b/lib/check-status-code.js index 591b156..95b4833 100644 --- a/lib/check-status-code.js +++ b/lib/check-status-code.js @@ -41,7 +41,12 @@ function axiosRequest(urlToCheck, axiosOptions, redirect) { if (error.response && error.response.status) { httpStatus[2] = error.response.status; if (error.response.status >= 300 && error.response.status < 400) { - const redUrl = error.response.headers.location; + let redUrl = error.response.headers.location; + // if relative url, prepend the current protocol and hostname + if(redUrl.startsWith('/')){ + const url = new URL(urlToCheck); + redUrl = `${url.protocol}//${url.hostname}${redUrl}`; + } const checkType = await axiosRequest(redUrl, axiosOptions, true); httpStatus[3] = error.response.headers.location;