Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix content-length calcuation in Rack:Response#write #2150

Merged
merged 1 commit into from Jan 31, 2024

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

test/spec_response.rb Show resolved Hide resolved
test/spec_response.rb Show resolved Hide resolved
test/spec_response.rb Show resolved Hide resolved
@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
15 of 16 checks passed
@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