OpenAPI: Parse body optionally in proxy

This commit is contained in:
Fuma Nama
2025-06-16 22:35:34 +08:00
parent 1d9ac05425
commit b1f805a99f
2 changed files with 13 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-openapi': patch
---
Parse body optionally in proxy
+8 -1
View File
@@ -78,11 +78,18 @@ export function createProxy(options: CreateProxyOptions = {}): Proxy {
);
}
const contentLength = req.headers.get('content-length');
const hasBody = contentLength && parseInt(contentLength) > 0;
let proxied = new Request(parsedUrl, {
method: req.method,
cache: 'no-cache',
headers: req.headers,
body: await req.arrayBuffer(),
body:
hasBody &&
['POST', 'PUT', 'PATCH', 'DELETE'].includes(req.method.toUpperCase())
? await req.arrayBuffer()
: undefined,
});
if (overrides?.request) {