diff options
author | raggi <jftucker@gmail.com> | 2010-10-04 13:00:25 -0300 |
---|---|---|
committer | raggi <jftucker@gmail.com> | 2010-10-04 21:50:32 -0300 |
commit | 50cdd0bf000a9ffb3eb3760fda2ff3e1ad18f3a7 (patch) | |
tree | 15534d460555fa699e91fe3ddc2a87bcc79dad9b | |
parent | f76e1bae9eac1cbb1e7b0b2846e6a0f8e42f9256 (diff) | |
download | rack-50cdd0bf000a9ffb3eb3760fda2ff3e1ad18f3a7.tar.gz |
release semantics of Rack::Chunked and Rack::ContentLength from handlers. this should not be forced on users.
-rw-r--r-- | lib/rack/content_length.rb | 6 | ||||
-rw-r--r-- | lib/rack/handler/cgi.rb | 2 | ||||
-rw-r--r-- | lib/rack/handler/fastcgi.rb | 2 | ||||
-rw-r--r-- | lib/rack/handler/lsws.rb | 2 | ||||
-rw-r--r-- | lib/rack/handler/mongrel.rb | 2 | ||||
-rw-r--r-- | lib/rack/handler/scgi.rb | 2 | ||||
-rw-r--r-- | lib/rack/handler/thin.rb | 1 | ||||
-rw-r--r-- | lib/rack/handler/webrick.rb | 2 | ||||
-rw-r--r-- | lib/rack/server.rb | 8 | ||||
-rw-r--r-- | test/spec_content_length.rb | 6 |
10 files changed, 13 insertions, 20 deletions
diff --git a/lib/rack/content_length.rb b/lib/rack/content_length.rb index ba72ef2c..32f31142 100644 --- a/lib/rack/content_length.rb +++ b/lib/rack/content_length.rb @@ -16,10 +16,10 @@ module Rack if !STATUS_WITH_NO_ENTITY_BODY.include?(status.to_i) && !headers['Content-Length'] && !headers['Transfer-Encoding'] && - (body.respond_to?(:to_ary) || body.respond_to?(:to_str)) + body.respond_to?(:to_ary) - body = [body] if body.respond_to?(:to_str) # rack 0.4 compat - length = body.to_ary.inject(0) { |len, part| len + bytesize(part) } + length = 0 + body.each { |part| length += bytesize(part) } headers['Content-Length'] = length.to_s end diff --git a/lib/rack/handler/cgi.rb b/lib/rack/handler/cgi.rb index cae7adae..15af1ac2 100644 --- a/lib/rack/handler/cgi.rb +++ b/lib/rack/handler/cgi.rb @@ -10,8 +10,6 @@ module Rack end def self.serve(app) - app = ContentLength.new(app) - env = ENV.to_hash env.delete "HTTP_CONTENT_LENGTH" diff --git a/lib/rack/handler/fastcgi.rb b/lib/rack/handler/fastcgi.rb index 9c94ca5b..8fa24d72 100644 --- a/lib/rack/handler/fastcgi.rb +++ b/lib/rack/handler/fastcgi.rb @@ -27,8 +27,6 @@ module Rack end def self.serve(request, app) - app = Rack::ContentLength.new(app) - env = request.env env.delete "HTTP_CONTENT_LENGTH" diff --git a/lib/rack/handler/lsws.rb b/lib/rack/handler/lsws.rb index 3e699920..1dee78a3 100644 --- a/lib/rack/handler/lsws.rb +++ b/lib/rack/handler/lsws.rb @@ -11,8 +11,6 @@ module Rack end end def self.serve(app) - app = Rack::ContentLength.new(app) - env = ENV.to_hash env.delete "HTTP_CONTENT_LENGTH" env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/" diff --git a/lib/rack/handler/mongrel.rb b/lib/rack/handler/mongrel.rb index 0d8125a4..e4372918 100644 --- a/lib/rack/handler/mongrel.rb +++ b/lib/rack/handler/mongrel.rb @@ -39,7 +39,7 @@ module Rack end def initialize(app) - @app = Rack::Chunked.new(Rack::ContentLength.new(app)) + @app = app end def process(request, response) diff --git a/lib/rack/handler/scgi.rb b/lib/rack/handler/scgi.rb index d0384785..39e23aad 100644 --- a/lib/rack/handler/scgi.rb +++ b/lib/rack/handler/scgi.rb @@ -16,7 +16,7 @@ module Rack end def initialize(settings = {}) - @app = Rack::Chunked.new(Rack::ContentLength.new(settings[:app])) + @app = settings[:app] super(settings) end diff --git a/lib/rack/handler/thin.rb b/lib/rack/handler/thin.rb index 3d4fedff..b6de4c20 100644 --- a/lib/rack/handler/thin.rb +++ b/lib/rack/handler/thin.rb @@ -6,7 +6,6 @@ module Rack module Handler class Thin def self.run(app, options={}) - app = Rack::Chunked.new(Rack::ContentLength.new(app)) server = ::Thin::Server.new(options[:Host] || '0.0.0.0', options[:Port] || 8080, app) diff --git a/lib/rack/handler/webrick.rb b/lib/rack/handler/webrick.rb index 263b0192..342e4434 100644 --- a/lib/rack/handler/webrick.rb +++ b/lib/rack/handler/webrick.rb @@ -20,7 +20,7 @@ module Rack def initialize(server, app) super server - @app = Rack::ContentLength.new(app) + @app = app end def service(req, res) diff --git a/lib/rack/server.rb b/lib/rack/server.rb index d04aced9..176c1331 100644 --- a/lib/rack/server.rb +++ b/lib/rack/server.rb @@ -169,7 +169,13 @@ module Rack def self.middleware @middleware ||= begin m = Hash.new {|h,k| h[k] = []} - m["deployment"].concat [lambda {|server| server.server.name =~ /CGI/ ? nil : [Rack::CommonLogger, $stderr] }] + m["deployment"].concat [ + [Rack::Chunked], + [Rack::ContentLength], + lambda { |server| + server.server.name =~ /CGI/ ? nil : [Rack::CommonLogger, $stderr] + } + ] m["development"].concat m["deployment"] + [[Rack::ShowExceptions], [Rack::Lint]] m end diff --git a/test/spec_content_length.rb b/test/spec_content_length.rb index 904992ff..68d9270a 100644 --- a/test/spec_content_length.rb +++ b/test/spec_content_length.rb @@ -1,12 +1,6 @@ require 'rack/content_length' describe Rack::ContentLength do - should "set Content-Length on String bodies if none is set" do - app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] } - response = Rack::ContentLength.new(app).call({}) - response[1]['Content-Length'].should.equal '13' - end - should "set Content-Length on Array bodies if none is set" do app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]] } response = Rack::ContentLength.new(app).call({}) |