Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ContentLength has been merged into rack core '5b60d28'

  • Loading branch information...
commit aef9ef8c1c8119025a79f134312cc9cda3423ccc 1 parent 3560ac0
@josh josh authored
View
3  README.rdoc
@@ -3,8 +3,6 @@
This package includes a variety of add-on components for Rack, a Ruby web server
interface:
-* Rack::ContentLength - Automatically sets the Content-Length header on
- all String bodies.
* Rack::ETag - Automatically sets the ETag header on all String bodies.
* Rack::JSONP - Adds JSON-P support by stripping out the callback param
and padding the response with the appropriate callback format.
@@ -44,7 +42,6 @@ components included. The following example shows what a simple rackup
use Rack::Profiler if ENV['RACK_ENV'] == 'development'
use Rack::ETag
- use Rack::ContentLength
use Rack::MailExceptions
run theapp
View
22 lib/rack/content_length.rb
@@ -1,22 +0,0 @@
-module Rack
- # Automatically sets the Content-Length header on all String bodies
- class ContentLength
- STATUS_WITH_NO_ENTITY_BODY = (100..199).to_a << 204 << 304
-
- def initialize(app)
- @app = app
- end
-
- def call(env)
- status, headers, body = @app.call(env)
-
- if !STATUS_WITH_NO_ENTITY_BODY.include?(status) &&
- !headers.has_key?('Content-Length') &&
- body.is_a?(String)
- headers['Content-Length'] = body.length.to_s
- end
-
- [status, headers, body]
- end
- end
-end
View
1  lib/rack/contrib.rb
@@ -6,7 +6,6 @@ def self.release
end
end
- autoload :ContentLength, "rack/content_length"
autoload :ETag, "rack/etag"
autoload :JSONP, "rack/jsonp"
autoload :LighttpdScriptNameFix, "rack/lighttpd_script_name_fix"
View
28 test/spec_rack_content_length.rb
@@ -1,28 +0,0 @@
-require 'rack/mock'
-require 'rack/content_length'
-
-context "Rack::ContentLength" do
- specify "sets Content-Length 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
-
- specify "does not change Content-Length if it is already set" do
- app = lambda { |env| [200, {'Content-Type' => 'text/plain', 'Content-Length' => '1'}, "Hello, World!"] }
- response = Rack::ContentLength.new(app).call({})
- response[1]['Content-Length'].should.equal '1'
- end
-
- specify "does not set Content-Length if on a 304 request" do
- app = lambda { |env| [304, {'Content-Type' => 'text/plain'}, ""] }
- response = Rack::ContentLength.new(app).call({})
- response[1]['Content-Length'].should.equal nil
- end
-
- specify "does not set Content-Length if steaming body" do
- app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, ["Hello", "World"]] }
- response = Rack::ContentLength.new(app).call({})
- response[1]['Content-Length'].should.equal nil
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.