Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

release semantics of Rack::Chunked and Rack::ContentLength from handl…

…ers. this should not be forced on users.
  • Loading branch information...
commit 50cdd0bf000a9ffb3eb3760fda2ff3e1ad18f3a7 1 parent f76e1ba
@raggi raggi authored
View
6 lib/rack/content_length.rb
@@ -16,10 +16,10 @@ def call(env)
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
View
2  lib/rack/handler/cgi.rb
@@ -10,8 +10,6 @@ def self.run(app, options=nil)
end
def self.serve(app)
- app = ContentLength.new(app)
-
env = ENV.to_hash
env.delete "HTTP_CONTENT_LENGTH"
View
2  lib/rack/handler/fastcgi.rb
@@ -27,8 +27,6 @@ def self.run(app, options={})
end
def self.serve(request, app)
- app = Rack::ContentLength.new(app)
-
env = request.env
env.delete "HTTP_CONTENT_LENGTH"
View
2  lib/rack/handler/lsws.rb
@@ -11,8 +11,6 @@ def self.run(app, options=nil)
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"] == "/"
View
2  lib/rack/handler/mongrel.rb
@@ -39,7 +39,7 @@ def self.run(app, options={})
end
def initialize(app)
- @app = Rack::Chunked.new(Rack::ContentLength.new(app))
+ @app = app
end
def process(request, response)
View
2  lib/rack/handler/scgi.rb
@@ -16,7 +16,7 @@ def self.run(app, options=nil)
end
def initialize(settings = {})
- @app = Rack::Chunked.new(Rack::ContentLength.new(settings[:app]))
+ @app = settings[:app]
super(settings)
end
View
1  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)
View
2  lib/rack/handler/webrick.rb
@@ -20,7 +20,7 @@ def self.shutdown
def initialize(server, app)
super server
- @app = Rack::ContentLength.new(app)
+ @app = app
end
def service(req, res)
View
8 lib/rack/server.rb
@@ -169,7 +169,13 @@ def app
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
View
6 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({})
Please sign in to comment.
Something went wrong with that request. Please try again.