Skip to content

Conversation

id3er0
Copy link
Contributor

@id3er0 id3er0 commented Aug 14, 2025

Description

Fixes "Parse Error: Invalid character in Content-Length" errors that occur when S3-compatible storage providers (like MinIO) return undefined or invalid ContentLength values.

Changes

  • Added validation before appending Content-Length header in staticHandler.ts
  • Only appends Content-Length when value is present and numeric
  • Prevents HTTP specification violations from undefined/invalid values

Code Changes

const contentLength = String(object.ContentLength);
if (contentLength && !isNaN(Number(contentLength))) {
  headers.append('Content-Length', contentLength);
}

Issue

  • Resolves MinIO compatibility issues where undefined ContentLength causes client parse errors
  • Maintains backward compatibility when ContentLength is valid

Testing

  • Tested with MinIO provider returning undefined ContentLength
  • Verified valid Content-Length values are still properly set
  • Confirmed no regression in existing S3 functionality

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Prevents "Parse Error: Invalid character in Content-Length" when S3-compatible 
providers return undefined ContentLength. Only appends header when value is 
present and numeric.

Fixes issue with MinIO returning undefined ContentLength values.
@id3er0 id3er0 requested a review from denolfe as a code owner August 14, 2025 00:42
@id3er0 id3er0 closed this Aug 14, 2025
@id3er0 id3er0 reopened this Aug 14, 2025
@DanRibbens DanRibbens merged commit 9d08f50 into payloadcms:main Aug 15, 2025
83 checks passed
Copy link
Contributor

🚀 This is included in version v3.53.0

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.

2 participants