Comments (4)
Without digging into it, it appears that the latter @length += chunk.bytesize
is incorrect. Do you think removing it is the correct course of action?
from rack.
I'm actually not sure I understand the intention of the existing code, in particular why @buffered
is set to nil
in the constructor and lazily initialized later. Since I may be missing the point of @buffered
, take what follows with a grain of salt.
The problem I see is that there is a missing assignment of @buffered
in one of the conditional branches within buffered_body!
.
Abbreviated, the code currently looks like this:
if @buffered.nil?
if @body.is_a?(Array)
# ...
# ⚠️ @buffered is not set in this branch
elsif @body.respond_to?(:each)
# ...
@buffered = true
else
@buffered = false
end
end
It seems like the point of this code was to lazily init @buffered
to true or false, but currently that isn't happening in the first branch. So I think the fix is to add @buffered = true
, like this:
--- lib/rack/response.rb
+++ lib/rack/response.rb
@@ -318,12 +318,14 @@ module Rack
if @body.is_a?(Array)
# The user supplied body was an array:
@body = @body.compact
@body.each do |part|
@length += part.to_s.bytesize
end
+
+ @buffered = true
elsif @body.respond_to?(:each)
# Turn the user supplied body into a buffered array:
body = @body
@body = Array.new
body.each do |part|
With this one-line change, I get the correct content-length result when running my reproduction script.
from rack.
Do you mind making a PR?
from rack.
OK, I've opened PR #2150
from rack.
Related Issues (20)
- Cookie being created with [" prefixed to name versions 3.0 thru 3.0.8 HOT 7
- Support for `Partitioned` cookie attribute HOT 16
- can't rackup HOT 5
- Rack::Lint::LintError: Status must be >=100 seen as integer HOT 10
- How to manually decode a Rack::Session::Cookie 2023 HOT 1
- 3.0.8 Multipart PATCH requests fail in minitest(Rack::Multipart::EmptyContentError) HOT 2
- HTTP_VERSION vs SERVER_PROTOCOL and Rack::Lint HOT 5
- Spec ambiguity: environment instance HOT 11
- undefined method `[]' for nil:NilClass HOT 1
- 3.0.9 not visible in releases nor changelog HOT 2
- RACK_INPUT not rewound on form data HOT 2
- Upgrading from rack ~> 2.2 to >= 3.0.0 required me to do a new request.body.rewind before a request.body.read HOT 2
- Rack v2.2.8 release and changelog is missing HOT 2
- how to listen host Loopback HOT 2
- Request for release - EOFError on empty multipart request HOT 6
- Support for zstd in Deflater HOT 5
- Discrepancy in the parsing behavior of Rack::Multipart between versions 1.6 and 2.2 HOT 8
- Deprecation should note how to fix HOT 3
- ostruct warning with Ruby 3.4.0preview1 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rack.