From 29e0b9e5d25a06895151e1b4e6c0f25db77fa267 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Thu, 9 Nov 2023 17:26:04 -0800 Subject: [PATCH] Better default request names --- src-web/components/Sidebar.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src-web/components/Sidebar.tsx b/src-web/components/Sidebar.tsx index f8ad22e0..639de5a3 100644 --- a/src-web/components/Sidebar.tsx +++ b/src-web/components/Sidebar.tsx @@ -782,10 +782,15 @@ function defaultRequestName(r: HttpRequest): string | null { return ''; } + const fixedUrl = r.url.match(/^https?:\/\//) ? r.url : 'http://' + r.url; + try { - const url = new URL(r.url); - return url.pathname != '/' ? url.host + url.pathname : url.host; + const url = new URL(fixedUrl); + const pathname = url.pathname === '/' ? '' : url.pathname; + return `${url.host}${pathname}`; } catch (_) { - return r.url; + // Nothing } + + return null; }