diff options
author | José Valim <jose.valim@gmail.com> | 2011-05-20 22:20:51 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-05-20 22:20:51 +0200 |
commit | 5eadb4d73dc5384509efeea3b9584ded19956c7b (patch) | |
tree | d44cb17e3646c9dfec5a6a6abc2d42f551f1dfe6 /railties/lib/rails/rack | |
parent | 19ee8413deee4bf202e87d53bf6d99b24a795ac8 (diff) | |
download | rails-5eadb4d73dc5384509efeea3b9584ded19956c7b.tar.gz rails-5eadb4d73dc5384509efeea3b9584ded19956c7b.tar.bz2 rails-5eadb4d73dc5384509efeea3b9584ded19956c7b.zip |
Temporarily ship with ContentLength middleware.
Diffstat (limited to 'railties/lib/rails/rack')
-rw-r--r-- | railties/lib/rails/rack/content_length.rb | 38 | ||||
-rw-r--r-- | railties/lib/rails/rack/static.rb | 5 |
2 files changed, 38 insertions, 5 deletions
diff --git a/railties/lib/rails/rack/content_length.rb b/railties/lib/rails/rack/content_length.rb new file mode 100644 index 0000000000..6839af4152 --- /dev/null +++ b/railties/lib/rails/rack/content_length.rb @@ -0,0 +1,38 @@ +require 'action_dispatch' +require 'rack/utils' + +module Rails + module Rack + # Sets the Content-Length header on responses with fixed-length bodies. + class ContentLength + include ::Rack::Utils + + def initialize(app, sendfile=nil) + @app = app + @sendfile = sendfile + 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'] && + !(@sendfile && headers[@sendfile]) + + old_body = body + body, length = [], 0 + old_body.each do |part| + body << part + length += bytesize(part) + end + old_body.close if old_body.respond_to?(:close) + headers['Content-Length'] = length.to_s + end + + [status, headers, body] + end + end + end +end
\ No newline at end of file diff --git a/railties/lib/rails/rack/static.rb b/railties/lib/rails/rack/static.rb deleted file mode 100644 index ebe8b9e103..0000000000 --- a/railties/lib/rails/rack/static.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'action_dispatch' - -module Rails::Rack - Static = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('Rails::Rack::Static', ActionDispatch::Static) -end |