From 95600cf6da1c6fbd5ee9f1a5de57b17503d4fe9c Mon Sep 17 00:00:00 2001
From: Tom van der Lee <tom@vanderlee.io>
Date: Tue, 30 Jun 2026 22:23:27 +0200
Subject: Filter based on subdomains

---
 src/components/RequestList/RequestList.tsx | 50 ++++++++++++++++++++++++++++--
 1 file changed, 48 insertions(+), 2 deletions(-)

(limited to 'src/components/RequestList/RequestList.tsx')

diff --git a/src/components/RequestList/RequestList.tsx b/src/components/RequestList/RequestList.tsx
index 8217229..1ab53d8 100644
--- a/src/components/RequestList/RequestList.tsx
+++ b/src/components/RequestList/RequestList.tsx
@@ -21,9 +21,14 @@ type EnabledMethods = {
   [method in Method]: boolean;
 };
 
+type EnabledHosts = {
+  [host: string]: boolean;
+};
+
 export default function RequestList() {
   const { darkMode } = useContext(SettingsContext);
   const {
+    config,
     calls: requests,
     selectedCall,
     setSelectedCall,
@@ -33,6 +38,20 @@ export default function RequestList() {
   const [search, setSearch] = useState("");
   const [enableRegex, setEnableRegex] = useState(false);
 
+  const [hosts, setHosts] = useState<EnabledHosts>({});
+
+  useEffect(() => {
+    setHosts((oldValues) =>
+      (config?.urls ?? []).reduce((acc, url) => {
+        const { host } = new URL(url);
+        return {
+          ...acc,
+          [host]: oldValues[host] ?? true,
+        };
+      }, {})
+    );
+  }, [config?.urls]);
+
   const [methods, setMethods] = useState<EnabledMethods>({
     GET: true,
     HEAD: true,
@@ -95,6 +114,17 @@ export default function RequestList() {
 
     return requests
       .reverse()
+      .filter((request) => {
+        const [_, hostHeader] = request.request.headers.find(
+          ([key]) => key.toLowerCase() === "host"
+        ) ?? [null, null];
+
+        if (hostHeader === null) {
+          return true;
+        }
+
+        return hosts[hostHeader] ?? false;
+      })
       .filter(
         (request) =>
           enabledMethods.length === 0 ||
@@ -103,7 +133,7 @@ export default function RequestList() {
       .filter(
         (request) => search === "" || searchRegex.test(request.request.path)
       );
-  }, [requests, search, enabledMethods, enableRegex]);
+  }, [requests, search, hosts, enabledMethods, enableRegex]);
 
   return (
     <div className={classNames(styles.listContainer, "d-flex")}>
@@ -204,6 +234,20 @@ export default function RequestList() {
               onChange={() => setEnableRegex(!enableRegex)}
             />
           </Form.Group>
+          <Form.Group className="mb-4">
+            <Form.Label className="fw-bold">Hosts</Form.Label>
+            {Object.entries(hosts).map(([host, enabled]) => (
+              <Form.Check
+                key={host}
+                type="switch"
+                label={host}
+                checked={enabled}
+                onChange={() =>
+                  setHosts((values) => ({ ...values, [host]: !enabled }))
+                }
+              />
+            ))}
+          </Form.Group>
           <Form.Group className="mb-4">
             <Form.Label className="fw-bold">Method</Form.Label>
             {Object.entries(methods).map(([method, enabled]) => (
@@ -212,7 +256,9 @@ export default function RequestList() {
                 type="switch"
                 label={method}
                 checked={enabled}
-                onChange={() => setMethods({ ...methods, [method]: !enabled })}
+                onChange={() =>
+                  setMethods((values) => ({ ...values, [method]: !enabled }))
+                }
               />
             ))}
           </Form.Group>
-- 
cgit v1.2.3

