Revert "Enhancement: forward cookies from request (#1804)" (#1946)

This reverts commit d4edd432d8.
pull/1955/head
shamoon 1 year ago committed by GitHub
parent 4f1cde97ec
commit 95635fca04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,7 +3,6 @@ import { performance } from "perf_hooks";
import { getServiceItem } from "utils/config/service-helpers"; import { getServiceItem } from "utils/config/service-helpers";
import createLogger from "utils/logger"; import createLogger from "utils/logger";
import { httpProxy } from "utils/proxy/http"; import { httpProxy } from "utils/proxy/http";
import {importCookieHeader} from "utils/proxy/cookie-jar";
const logger = createLogger("ping"); const logger = createLogger("ping");
@ -26,24 +25,20 @@ export default async function handler(req, res) {
}); });
} }
if (req.headers.cookie) {
importCookieHeader(pingURL, req.headers.cookie)
}
try { try {
let startTime = performance.now(); let startTime = performance.now();
let [status] = await httpProxy(pingURL, { let [status] = await httpProxy(pingURL, {
method: "HEAD" method: "HEAD"
}); });
let endTime = performance.now(); let endTime = performance.now();
if (status > 403) { if (status > 403) {
// try one more time as a GET in case HEAD is rejected for whatever reason // try one more time as a GET in case HEAD is rejected for whatever reason
startTime = performance.now(); startTime = performance.now();
[status] = await httpProxy(pingURL); [status] = await httpProxy(pingURL);
endTime = performance.now(); endTime = performance.now();
} }
return res.status(200).json({ return res.status(200).json({
status, status,
latency: endTime - startTime latency: endTime - startTime

@ -37,27 +37,3 @@ export function addCookieToJar(url, headers) {
cookieJar.setCookieSync(cookies[i], url.toString(), { ignoreError: true }); cookieJar.setCookieSync(cookies[i], url.toString(), { ignoreError: true });
} }
} }
export function importCookieHeader(url, cookieHeader) {
const cookies = cookieHeader.split(';');
for (let i = 0; i < cookies.length; i += 1) {
const [key, value] = cookies[i].trim().split('=');
// If there's an existing cookie with a matching key for this url,
// we want to update it. Otherwise, we add a new cookie
let existingCookie;
try {
existingCookie = cookieJar.getCookiesSync(url).find(existing => existing.key === key);
} catch (e) {
console.debug(`Failed to get cookies for ${url}: ${e}`)
}
if (existingCookie) {
existingCookie.value = value;
} else {
cookieJar.setCookieSync(new Cookie({
key, value
}), url.toString(), { ignoreError: true });
}
}
}

@ -4,7 +4,6 @@ import validateWidgetData from "utils/proxy/validate-widget-data";
import { httpProxy } from "utils/proxy/http"; import { httpProxy } from "utils/proxy/http";
import createLogger from "utils/logger"; import createLogger from "utils/logger";
import widgets from "widgets/widgets"; import widgets from "widgets/widgets";
import {importCookieHeader} from "utils/proxy/cookie-jar";
const logger = createLogger("genericProxyHandler"); const logger = createLogger("genericProxyHandler");
@ -35,18 +34,14 @@ export default async function genericProxyHandler(req, res, map) {
params.body = req.body; params.body = req.body;
} }
if (req.headers.cookie) {
importCookieHeader(url, req.headers.cookie)
}
const [status, contentType, data] = await httpProxy(url, params); const [status, contentType, data] = await httpProxy(url, params);
let resultData = data; let resultData = data;
if (resultData.error?.url) { if (resultData.error?.url) {
resultData.error.url = sanitizeErrorURL(url); resultData.error.url = sanitizeErrorURL(url);
} }
if (status === 200) { if (status === 200) {
if (!validateWidgetData(widget, endpoint, resultData)) { if (!validateWidgetData(widget, endpoint, resultData)) {
return res.status(status).json({error: {message: "Invalid data", url: sanitizeErrorURL(url), data: resultData}}); return res.status(status).json({error: {message: "Invalid data", url: sanitizeErrorURL(url), data: resultData}});

Loading…
Cancel
Save