Skip to content

Conversation

mattbrictson
Copy link
Contributor

@mattbrictson mattbrictson commented Jan 30, 2024

When Rack::Response is initialized with an Array, it properly sets its internal @length value and emitted content-length header on the first use of write. But every subsequent time write is called, it increments the length incorrectly, resulting in an incorrect content-length header.

This commit fixes the accumulation bug, and fixes/adds specs to properly test the scenario where write is used multiple times.

Fixes #2148

@mattbrictson
Copy link
Contributor Author

The jruby CI failures seem unrelated?

When `Rack::Response` is initialized with an Array, it incorrectly
increments its internal `@length` value and emitted content-length
header on every subsequent write. The more times `write` is called, the
more the error accumulates.

This commit fixes the accumulation bug, and fixes/adds specs to properly
test the scenario where `write` is used multiple times.
@ioquatix ioquatix merged commit e50b72a into rack:main Jan 31, 2024
@ioquatix
Copy link
Member

Thanks for your contribution. @jeremyevans as this is a bug fix should we consider back porting to 3.0?

@jeremyevans
Copy link
Contributor

Sure, this seems reasonable to backport.

ioquatix pushed a commit that referenced this pull request Jan 31, 2024
When `Rack::Response` is initialized with an Array, it incorrectly
increments its internal `@length` value and emitted content-length
header on every subsequent write. The more times `write` is called, the
more the error accumulates.

This commit fixes the accumulation bug, and fixes/adds specs to properly
test the scenario where `write` is used multiple times.
@ioquatix ioquatix added this to the v3.0.9 milestone Jan 31, 2024
@mattbrictson mattbrictson deleted the fix-content-length branch January 31, 2024 16:03
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.

Multiple writes to Rack::Response result in incorrect content-length header in Rack 3
3 participants