Add HTTP request tool
diff --git a/public/favicon.ico b/public/favicon.ico
deleted file mode 100644
index 8830cf6..0000000
--- a/public/favicon.ico
+++ /dev/null
Binary files differ
diff --git a/remix.config.js b/remix.config.js
index 148a89f..c2df613 100644
--- a/remix.config.js
+++ b/remix.config.js
@@ -2,7 +2,7 @@
module.exports = {
serverBuildTarget: "cloudflare-workers",
server: "./src/worker/index.ts",
- devServerBroadcastDelay: 1000,
+ //devServerBroadcastDelay: 1000,
ignoredRouteFiles: ["**/.*"],
appDirectory: "src/app",
assetsBuildDirectory: "public/dist",
diff --git a/src/app/components/NavRoot.tsx b/src/app/components/NavRoot.tsx
index 3663d20..214025d 100644
--- a/src/app/components/NavRoot.tsx
+++ b/src/app/components/NavRoot.tsx
@@ -1,5 +1,5 @@
import React from "react";
-import { Navbar, Sidebar, Container, Clickable, SidebarItem, SidebarGroup } from "shamrock-ux";
+import { Navbar, Sidebar, Container, Clickable, SidebarItem, SidebarGroup, Icon } from "shamrock-ux";
import { useLoaderData, useLocation, useNavigate } from "@remix-run/react";
import tools from "../tools";
import IPDetailsPage from "./ip/IPDetailsPage";
@@ -40,7 +40,18 @@
return (
<div className="h-full">
- <Navbar title="WebDiag" logo="https://emoji.jottocraft.com/highres/1f9f0.svg" logoFullWidth>
+ <Navbar title="WebDiag" logo="https://emoji.jottocraft.com/highres/1f9f0.svg" logoFullWidth widgets={{
+ right: (
+ <div>
+ <Clickable href="https://jottocraft.com/feedback/?key=burya">
+ <div className="font-medium flex flex-row items-center space-x-1">
+ <Icon className="text-2xl">💡</Icon>
+ <span>Feedback</span>
+ </div>
+ </Clickable>
+ </div>
+ )
+ }}>
<Sidebar items={tools.map(group => {
group.items.forEach((tool: SidebarItem & { id: string; }) => {
const pathname = `/${tool.id}`;
diff --git a/src/app/root.tsx b/src/app/root.tsx
index c2742e3..1b1e0cb 100644
--- a/src/app/root.tsx
+++ b/src/app/root.tsx
@@ -50,18 +50,18 @@
<Theme styles={{
dark: {
accent: {
- type: "#828bff",
+ type: "#ff5b82",
element: {
- ui: "#9097ff",
- type: "#0d144c"
+ ui: "#ff5b82",
+ type: "#400e1c"
}
}
},
light: {
accent: {
- type: "#5862cf",
+ type: "#cb2c5a",
element: {
- ui: "#4852c0",
+ ui: "#cb2c5a",
type: "#ededed"
}
}
diff --git a/src/app/routes/http.tsx b/src/app/routes/http.tsx
new file mode 100644
index 0000000..d2178c4
--- /dev/null
+++ b/src/app/routes/http.tsx
@@ -0,0 +1,66 @@
+import { HeadersFunction, LoaderFunction } from "@remix-run/cloudflare";
+import { useLoaderData } from "@remix-run/react";
+import React from "react";
+import { Helmet } from "react-helmet-async";
+import { Icon, Link } from "shamrock-ux";
+import StatusBox from "../components/StatusBox";
+import httpEcho, { SerializedRequestInfo } from "../util/http/httpEcho";
+
+export const loader: LoaderFunction = async ({ request, context }) => {
+ return httpEcho(request, context.cf as IncomingRequestCfProperties);
+};
+
+function KVGroup({ data, cat, icon, desc }: { data: [string, string][]; cat?: string; icon?: string; desc?: string; }) {
+ if (!data.length) return null;
+ return (
+ <div className="space-y-4">
+ {cat && icon ? (
+ <div>
+ <div className="font-medium text-type-20 flex flex-row items-center space-x-1">
+ <Icon>{icon}</Icon>
+ <h5>{cat}</h5>
+ </div>
+ {desc ? <p className="text-sm text-type-30">{desc}</p> : null}
+ </div>
+ ) : null}
+ <div>
+ <table>
+ <tbody>
+ {data.map(([headerName, headerValue]) => (
+ <tr className="text-sm">
+ <td className="pr-6 font-medium text-type-30">{headerName}:</td>
+ <td className="text-type-40">{headerValue}</td>
+ </tr>
+ ))}
+ </tbody>
+ </table>
+ </div>
+ </div>
+ );
+}
+
+export default function HTTPRequest() {
+ const data = useLoaderData() as SerializedRequestInfo;
+
+ return (
+ <>
+ <Helmet>
+ <title>HTTP Request</title>
+ </Helmet>
+ <div className="space-y-12">
+ <div className="flex flex-row items-center space-x-10">
+ <h1 className="text-2xl font-medium text-type-10">{data.method}</h1>
+ <h2 className="text-2xl text-type-20 flex-shrink truncate">{data.url}</h2>
+ <h3 className="text-xl text-type-40 flex-grow text-right">{data.proto}</h3>
+ </div>
+ <KVGroup data={data.searchParams} cat="URL query parameters" icon="link" />
+ <KVGroup data={data.headers.base} cat="Headers" icon="format_list_bulleted" />
+ <KVGroup data={data.headers.secCH} cat="Client hints" icon="devices" desc="These headers were specifically requested for WebDiag's User Agent tool and may not be present in a typical HTTP request" />
+ <KVGroup data={data.headers.cf} cat="Cloudflare proxy headers" icon="multiple_stop" desc="These headers were added by the Cloudflare reverse proxy used by WebDiag and may not be present in your original request" />
+ <StatusBox type="info">
+ <p>This tool only accepts GET requests, as it's intended to be used in a browser. If you'd like to troubleshoot more complicated HTTP requests, try using <Link href="https://echo.jottocraft.com">echo.jottocraft.com</Link>.</p>
+ </StatusBox>
+ </div>
+ </>
+ );
+}
\ No newline at end of file
diff --git a/src/app/routes/ip.tsx b/src/app/routes/ip.tsx
index 9d846eb..446c235 100644
--- a/src/app/routes/ip.tsx
+++ b/src/app/routes/ip.tsx
@@ -3,7 +3,7 @@
import IPDetailsPage from "../components/ip/IPDetailsPage";
export const loader: LoaderFunction = async ({ request, context }) => {
- return getIPData(request, (context as any).cf);
+ return getIPData(request, context.cf as IncomingRequestCfProperties);
};
export default function IPAddress() {
diff --git a/src/app/routes/ua.tsx b/src/app/routes/ua.tsx
index f06c21d..6334f85 100644
--- a/src/app/routes/ua.tsx
+++ b/src/app/routes/ua.tsx
@@ -1,32 +1,17 @@
import { HeadersFunction, LoaderFunction } from "@remix-run/cloudflare";
import { useLoaderData } from "@remix-run/react";
import React from "react";
+import { Helmet } from "react-helmet-async";
import { Link } from "shamrock-ux";
import StatusBox from "../components/StatusBox";
-import LegacyUA from "../components/ua/legacyUA";
-import SecCH from "../components/ua/secCH";
+import LegacyUA from "../components/ua/LegacyUA";
+import SecCH from "../components/ua/SecCH";
import Widget from "../components/Widget";
import loadParseUA, { AvailableUAData } from "../util/ua/loadParseUA";
-
-const ClientHints = [
- "Sec-CH-UA",
- "Sec-CH-Prefers-Color-Scheme",
- "Sec-CH-Prefers-Reduced-Motion",
- "Sec-CH-UA-Arch",
- "Sec-CH-UA-Bitness",
- "Sec-CH-UA-Full-Version-List",
- "Sec-CH-UA-Mobile",
- "Sec-CH-UA-Model",
- "Sec-CH-UA-Platform",
- "Sec-CH-UA-Platform-Version",
- "Downlink",
- "ECT",
- "RTT",
- "Save-Data"
-];
+import secCHHeaders from "../util/ua/secCHHeaders";
export const headers: HeadersFunction = () => {
- const CHstr = ClientHints.join(", ");
+ const CHstr = secCHHeaders.join(", ");
return {
"Accept-CH": CHstr,
"Vary": CHstr,
@@ -41,7 +26,18 @@
export default function UserAgent() {
const data = useLoaderData() as AvailableUAData;
- if (data?.from === "sec-ch") return <SecCH />;
- if (data?.from === "ua") return <LegacyUA />;
- return <StatusBox type="error"><p>Your browser/device isn't sending any user agent information</p></StatusBox>;
+ return (
+ <>
+ <Helmet>
+ <title>User Agent</title>
+ </Helmet>
+ {data?.from === "sec-ch" ? (
+ <SecCH />
+ ) : data?.from === "ua" ? (
+ <LegacyUA />
+ ) : (
+ <StatusBox type="error"><p>Your browser/device isn't sending any user agent information</p></StatusBox>
+ )}
+ </>
+ );
}
\ No newline at end of file
diff --git a/src/app/tools.ts b/src/app/tools.ts
index 4940c6a..17fcd52 100644
--- a/src/app/tools.ts
+++ b/src/app/tools.ts
@@ -3,7 +3,8 @@
type: "group", title: "Network info", icon: "🌐", items: [
{ name: "IP address", desc: "Get information about your public network", icon: "travel_explore", id: "ip" },
{ name: "User agent", desc: "Get information about your device and browser", icon: "devices", id: "ua" },
- // { name: "Full HTTP request", desc: "Show all the data your browser sends to load websites", icon: "swap_vert", id: "http" },
+ { name: "Browser HTTP request", desc: "Show all the data your browser sends to load websites", icon: "swap_vert", id: "http" },
+ // { name: "Connection info", desc: "Get information about how your browser establishes connections with web servers", icon: "cable", id: "con" },
// { name: "Query DNS", desc: "Resolve DNS names with public resolvers", icon: "dns", id: "dns" }
]
},
diff --git a/src/app/util/http/httpEcho.ts b/src/app/util/http/httpEcho.ts
new file mode 100644
index 0000000..4c4628e
--- /dev/null
+++ b/src/app/util/http/httpEcho.ts
@@ -0,0 +1,48 @@
+import secCHHeaders from "../ua/secCHHeaders";
+
+export type SerializedRequestInfo = {
+ method: Request["method"];
+ url: Request["url"];
+ proto: IncomingRequestCfProperties["httpProtocol"];
+ headers: {
+ secCH: [string, string][];
+ cf: [string, string][];
+ base: [string, string][];
+ };
+ searchParams: [string, string][];
+};
+
+export default function httpEcho(req: Request, cf: IncomingRequestCfProperties): SerializedRequestInfo {
+ const url = new URL(req.url);
+
+ const headers: SerializedRequestInfo["headers"] = {
+ secCH: [],
+ cf: [],
+ base: []
+ };
+ for (const header of req.headers.entries()) {
+ const headerName = header[0].toLowerCase();
+ if (headerName === "accept-encoding") header[1] = cf.clientAcceptEncoding ?? header[1];
+
+ if (secCHHeaders.find(h => h.toLowerCase() === headerName)) {
+ headers.secCH.push(header);
+ } else if (headerName.startsWith("cf-") || ["x-forwarded-proto", "x-real-ip"].includes(headerName)) {
+ headers.cf.push(header);
+ } else {
+ headers.base.push(header);
+ }
+ }
+
+ const searchParams: SerializedRequestInfo["searchParams"] = [];
+ for (const param of url.searchParams.entries()) {
+ searchParams.push(param);
+ }
+
+ return {
+ method: req.method,
+ url: req.url,
+ proto: cf.httpProtocol,
+ headers,
+ searchParams
+ }
+}
\ No newline at end of file
diff --git a/src/app/util/ua/secCHHeaders.ts b/src/app/util/ua/secCHHeaders.ts
new file mode 100644
index 0000000..77ed6ad
--- /dev/null
+++ b/src/app/util/ua/secCHHeaders.ts
@@ -0,0 +1,16 @@
+export default [
+ "Sec-CH-UA",
+ "Sec-CH-Prefers-Color-Scheme",
+ "Sec-CH-Prefers-Reduced-Motion",
+ "Sec-CH-UA-Arch",
+ "Sec-CH-UA-Bitness",
+ "Sec-CH-UA-Full-Version-List",
+ "Sec-CH-UA-Mobile",
+ "Sec-CH-UA-Model",
+ "Sec-CH-UA-Platform",
+ "Sec-CH-UA-Platform-Version",
+ "Downlink",
+ "ECT",
+ "RTT",
+ "Save-Data"
+];
\ No newline at end of file