mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-02 00:36:38 +00:00
update parser to handle h2c
This commit is contained in:
@@ -650,8 +650,8 @@ export default function ReverseProxyTargets(props: {
|
|||||||
className="min-w-[150px]"
|
className="min-w-[150px]"
|
||||||
onBlur={(e) => {
|
onBlur={(e) => {
|
||||||
const input = e.target.value.trim();
|
const input = e.target.value.trim();
|
||||||
const hasProtocol = /^https?:\/\//.test(input);
|
const hasProtocol = /^(https?|h2c):\/\//.test(input);
|
||||||
const hasPort = /:\d+/.test(input);
|
const hasPort = /:\d+(?:\/|$)/.test(input);
|
||||||
|
|
||||||
if (hasProtocol || hasPort) {
|
if (hasProtocol || hasPort) {
|
||||||
const parsed = parseHostTarget(input);
|
const parsed = parseHostTarget(input);
|
||||||
@@ -675,9 +675,7 @@ export default function ReverseProxyTargets(props: {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -973,8 +971,8 @@ export default function ReverseProxyTargets(props: {
|
|||||||
{...field}
|
{...field}
|
||||||
onBlur={(e) => {
|
onBlur={(e) => {
|
||||||
const input = e.target.value.trim();
|
const input = e.target.value.trim();
|
||||||
const hasProtocol = /^https?:\/\//.test(input);
|
const hasProtocol = /^(https?|h2c):\/\//.test(input);
|
||||||
const hasPort = /:\d+/.test(input);
|
const hasPort = /:\d+(?:\/|$)/.test(input);
|
||||||
|
|
||||||
if (hasProtocol || hasPort) {
|
if (hasProtocol || hasPort) {
|
||||||
const parsed = parseHostTarget(input);
|
const parsed = parseHostTarget(input);
|
||||||
|
|||||||
@@ -1,15 +1,29 @@
|
|||||||
|
|
||||||
export function parseHostTarget(input: string) {
|
export function parseHostTarget(input: string) {
|
||||||
try {
|
try {
|
||||||
const normalized = input.match(/^https?:\/\//) ? input : `http://${input}`;
|
const normalized = input.match(/^(https?|h2c):\/\//) ? input : `http://${input}`;
|
||||||
const url = new URL(normalized);
|
const url = new URL(normalized);
|
||||||
|
|
||||||
const protocol = url.protocol.replace(":", ""); // http | https
|
const protocol = url.protocol.replace(":", ""); // http | https | h2c
|
||||||
const host = url.hostname;
|
const host = url.hostname;
|
||||||
const port = url.port ? parseInt(url.port, 10) : protocol === "https" ? 443 : 80;
|
|
||||||
|
let defaultPort: number;
|
||||||
|
switch (protocol) {
|
||||||
|
case "https":
|
||||||
|
defaultPort = 443;
|
||||||
|
break;
|
||||||
|
case "h2c":
|
||||||
|
defaultPort = 80;
|
||||||
|
break;
|
||||||
|
default: // http
|
||||||
|
defaultPort = 80;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
const port = url.port ? parseInt(url.port, 10) : defaultPort;
|
||||||
|
|
||||||
return { protocol, host, port };
|
return { protocol, host, port };
|
||||||
} catch {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user