aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/vendor/rack-1.0/rack/content_length.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-02-07 00:08:28 -0600
committerJoshua Peek <josh@joshpeek.com>2009-02-07 00:08:28 -0600
commit2277fbedbea930fb8ce38ab7eb133de6fcc4a2d6 (patch)
tree784f2dfcd066eaa17a89cc435ec4de44393799c8 /actionpack/lib/action_controller/vendor/rack-1.0/rack/content_length.rb
parent24f2e676f700b8a387c6f4c27acf172658cd7863 (diff)
downloadrails-2277fbedbea930fb8ce38ab7eb133de6fcc4a2d6.tar.gz
rails-2277fbedbea930fb8ce38ab7eb133de6fcc4a2d6.tar.bz2
rails-2277fbedbea930fb8ce38ab7eb133de6fcc4a2d6.zip
Temporarily bundle Rack 1.0 prerelease for testing
Diffstat (limited to 'actionpack/lib/action_controller/vendor/rack-1.0/rack/content_length.rb')
-rw-r--r--actionpack/lib/action_controller/vendor/rack-1.0/rack/content_length.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/vendor/rack-1.0/rack/content_length.rb b/actionpack/lib/action_controller/vendor/rack-1.0/rack/content_length.rb
new file mode 100644
index 0000000000..bce22a32c5
--- /dev/null
+++ b/actionpack/lib/action_controller/vendor/rack-1.0/rack/content_length.rb
@@ -0,0 +1,27 @@
+require 'rack/utils'
+
+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