Skip to content

Conversation

@kaigritun
Copy link

Summary

Fixes #2574

When a proxy (like Cloudflare) strips the Content-Length header from an error response with no body, the client would return an empty string as the error value. Since empty string is falsy, this causes issues when checking if (error) - the code incorrectly treats it as "no error".

Changes

This fix applies the same safe handling to error responses that already exists for success responses. When Content-Length is absent and the body is empty:

  • Use response.text() first to get the raw content
  • If the raw content is empty, return undefined for the error value
  • This is consistent with the existing handling for status 204 and Content-Length: 0

Testing

Added two new test cases in delete.test.ts:

  1. Error response (500) with empty body and no Content-Length header
  2. Success response (200) with empty body and no Content-Length header (verifies existing behavior still works)

All 442 tests pass including the new ones.

Reproduction

// Simulate proxy stripping Content-Length header
global.fetch = async () => new Response(null, {
  status: 500,
  headers: {} // No Content-Length header
});

// Before fix: { error: "", response } - empty string is falsy
// After fix: { error: undefined, response } - consistent with 204 handling

…header is stripped

When a proxy (like Cloudflare) strips the Content-Length header from an
error response with no body, the client would return an empty string
as the error value, which is falsy and causes issues when checking
`if (error)`.

This fix applies the same safe handling to error responses that already
exists for success responses - when Content-Length is absent and the
body is empty, return undefined for the error value to be consistent
with 204 and Content-Length: 0 handling.

Fixes openapi-ts#2574
@kaigritun kaigritun requested a review from a team as a code owner February 10, 2026 04:19
@kaigritun kaigritun requested a review from drwpow February 10, 2026 04:19
@netlify
Copy link

netlify bot commented Feb 10, 2026

👷 Deploy request for openapi-ts pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit c11aa86

@changeset-bot
Copy link

changeset-bot bot commented Feb 10, 2026

⚠️ No Changeset found

Latest commit: c11aa86

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fails to parse responses when Content-Length header is stripped by proxy

1 participant