-
-
Notifications
You must be signed in to change notification settings - Fork 617
Labels
bugSomething isn't workingSomething isn't workingopenapi-fetchRelevant to the openapi-fetch libraryRelevant to the openapi-fetch library
Description
openapi-fetch version
0.13.8
Description
When a response with an empty body passes through Cloudflare (or other proxies), the client attempts to parse the empty response as JSON and fails. This happens because the current logic incorrectly treats the absence of a Content-Length header as indicating content is present.
Reproduction
// Mock server that returns empty body without Content-Length header
import express from 'express';
const app = express();
app.post('/test', (req, res) => {
res.removeHeader('Content-Length');
res.status(200).end();
});
app.listen(3000);Or simulate with fetch mock:
global.fetch = async () => new Response(null, {
status: 200,
headers: {} // No Content-Length header
});
// Now use openapi-fetch - it will fail trying to parse empty body as JSONExpected result
The client should gracefully handle empty responses regardless of whether the Content-Length header is present or absent. When a response has no body, response.data should be undefined or an appropriate empty value without attempting to parse it as JSON.
Extra
- I’m willing to open a PR (see CONTRIBUTING.md)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingopenapi-fetchRelevant to the openapi-fetch libraryRelevant to the openapi-fetch library