chore: refactor @packages/https-proxy to TypeScript and use vitest instead of mocha (#32718)

* chore: convert @packages/https-proxy to TypeScript and use vitest instead of mocha

* chore: address comments from code review

* Update packages/https-proxy/vitest.config.ts
This commit is contained in:
Bill Glesias
2025-10-15 14:00:41 -04:00
committed by GitHub
parent f31302c399
commit 4d904e272f
51 changed files with 1612 additions and 1536 deletions
+47
View File
@@ -0,0 +1,47 @@
import { parse } from 'url'
export function parseHost (hostString: string, defaultPort: number) {
let m
m = hostString.match(/^http:\/\/(.*)/)
if (m) {
const parsedUrl = parse(hostString)
return {
host: parsedUrl.hostname,
port: parsedUrl.port,
}
}
const hostPort = hostString.split(':')
const host = hostPort[0]
const port = hostPort.length === 2 ? +hostPort[1] : defaultPort
return {
host,
port,
}
}
export function hostAndPort (reqUrl: string, headers: any, defaultPort: number) {
let m
const {
host,
} = headers
const hostPort = parseHost(host, defaultPort)
// this handles paths which include the full url. This could happen if it's a proxy
m = reqUrl.match(/^http:\/\/([^\/]*)\/?(.*)$/)
if (m) {
const parsedUrl = parse(reqUrl)
hostPort.host = parsedUrl.hostname
hostPort.port = parsedUrl.port
reqUrl = parsedUrl.path
}
return hostPort
}