fixes http headers being set in wrong order

This commit is contained in:
nai-degen 2023-04-08 10:13:00 -05:00 committed by nai-degen
parent 45451c4486
commit c74c527f46
1 changed files with 7 additions and 8 deletions

View File

@ -22,17 +22,16 @@ const rewriteRequest = (proxyReq: http.ClientRequest, req: Request) => {
proxyReq.setHeader("Authorization", `Bearer ${key.key}`);
if (req.method === "POST" && req.body) {
if (req.body?.stream) {
req.body.stream = false;
const updatedBody = JSON.stringify(req.body);
proxyReq.setHeader("Content-Length", Buffer.byteLength(updatedBody));
(req as any).rawBody = Buffer.from(updatedBody);
}
// body-parser and http-proxy-middleware don't play nice together
fixRequestBody(proxyReq, req);
}
if (req.body?.stream) {
req.body.stream = false;
const updatedBody = JSON.stringify(req.body);
proxyReq.setHeader("Content-Length", Buffer.byteLength(updatedBody));
proxyReq.write(updatedBody);
proxyReq.end();
}
};
const openaiProxy = createProxyMiddleware({