lib/rack/content_length.rb in rack-2.1.4.4 vs lib/rack/content_length.rb in rack-2.2.0
- old
+ new
@@ -1,27 +1,26 @@
# frozen_string_literal: true
-require 'rack/utils'
-require 'rack/body_proxy'
-
module Rack
- # Sets the Content-Length header on responses with fixed-length bodies.
+ # Sets the Content-Length header on responses that do not specify
+ # a Content-Length or Transfer-Encoding header. Note that this
+ # does not fix responses that have an invalid Content-Length
+ # header specified.
class ContentLength
include Rack::Utils
def initialize(app)
@app = app
end
def call(env)
status, headers, body = @app.call(env)
- headers = HeaderHash.new(headers)
+ headers = HeaderHash[headers]
if !STATUS_WITH_NO_ENTITY_BODY.key?(status.to_i) &&
!headers[CONTENT_LENGTH] &&
- !headers[TRANSFER_ENCODING] &&
- body.respond_to?(:to_ary)
+ !headers[TRANSFER_ENCODING]
obody = body
body, length = [], 0
obody.each { |part| body << part; length += part.bytesize }