/usr/lib/ruby/vendor_ruby/rack/content_length.rb is in ruby-rack 1.6.4-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | require 'rack/utils'
require 'rack/body_proxy'
module Rack
# Sets the Content-Length header on responses with fixed-length bodies.
class ContentLength
include Rack::Utils
def initialize(app)
@app = app
end
def call(env)
status, headers, body = @app.call(env)
headers = HeaderHash.new(headers)
if !STATUS_WITH_NO_ENTITY_BODY.include?(status.to_i) &&
!headers[CONTENT_LENGTH] &&
!headers['Transfer-Encoding'] &&
body.respond_to?(:to_ary)
obody = body
body, length = [], 0
obody.each { |part| body << part; length += bytesize(part) }
body = BodyProxy.new(body) do
obody.close if obody.respond_to?(:close)
end
headers[CONTENT_LENGTH] = length.to_s
end
[status, headers, body]
end
end
end
|