Fix proxying non-ASCII (#6154)

This only affects the path proxy since `req.originalUrl` is in escaped format.
This commit is contained in:
smalllady 2023-04-26 03:41:33 +08:00 committed by GitHub
parent 2e17735795
commit 951d8ac45e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -11,7 +11,7 @@ const getProxyTarget = (req: Request, passthroughPath?: boolean): string => {
return `http://0.0.0.0:${req.params.port}/${req.originalUrl}`
}
const query = qs.stringify(req.query)
return `http://0.0.0.0:${req.params.port}/${req.params[0] || ""}${query ? `?${query}` : ""}`
return encodeURI(`http://0.0.0.0:${req.params.port}${req.params[0] || ""}${query ? `?${query}` : ""}`)
}
export async function proxy(

View File

@ -187,6 +187,17 @@ describe("proxy", () => {
})
}).rejects.toThrow()
})
it("should proxy non-ASCII", async () => {
e.get("*", (req, res) => {
res.json("ほげ")
})
codeServer = await integration.setup(["--auth=none"], "")
const resp = await codeServer.fetch(proxyPath.replace("wsup", "ほげ"))
expect(resp.status).toBe(200)
const json = await resp.json()
expect(json).toBe("ほげ")
})
})
// NOTE@jsjoeio