Sha256: b3163b86520fa6b6f4ffb4331dd1b3e16eebd4f7441e6cf1004c224540937581
Contents?: true
Size: 730 Bytes
Versions: 14
Compression:
Stored size: 730 Bytes
Contents
module Rack # Sets the Content-Length header on responses with fixed-length bodies. class ContentLength def initialize(app) @app = app end def call(env) status, headers, body = @app.call(env) headers = Utils::HeaderHash.new(headers) if !Utils::STATUS_WITH_NO_ENTITY_BODY.include?(status) && !headers['Content-Length'] && !headers['Transfer-Encoding'] && (body.respond_to?(:to_ary) || body.respond_to?(:to_str)) body = [body] if body.respond_to?(:to_str) # rack 0.4 compat length = body.to_ary.inject(0) { |len, part| len + part.length } headers['Content-Length'] = length.to_s end [status, headers, body] end end end
Version data entries
14 entries across 14 versions & 6 rubygems