Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 44 lines (36 sloc) 1.729 kB
5b60d28 @josh Add ContentLength middleware
josh authored
1 require 'rack/mock'
2 require 'rack/content_length'
3
4 context "Rack::ContentLength" do
7a0476b @rtomayko Rack::ContentLength tweaks ...
rtomayko authored
5 specify "sets Content-Length on String bodies if none is set" do
5b60d28 @josh Add ContentLength middleware
josh authored
6 app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] }
7 response = Rack::ContentLength.new(app).call({})
8 response[1]['Content-Length'].should.equal '13'
9 end
10
7a0476b @rtomayko Rack::ContentLength tweaks ...
rtomayko authored
11 specify "sets Content-Length on Array bodies if none is set" do
12 app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, ["Hello, World!"]] }
5b60d28 @josh Add ContentLength middleware
josh authored
13 response = Rack::ContentLength.new(app).call({})
14 response[1]['Content-Length'].should.equal '13'
15 end
16
7a0476b @rtomayko Rack::ContentLength tweaks ...
rtomayko authored
17 specify "does not set Content-Length on variable length bodies" do
18 body = lambda { "Hello World!" }
19 def body.each ; yield call ; end
20
21 app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, body] }
22 response = Rack::ContentLength.new(app).call({})
23 response[1]['Content-Length'].should.be.nil
24 end
25
5b60d28 @josh Add ContentLength middleware
josh authored
26 specify "does not change Content-Length if it is already set" do
27 app = lambda { |env| [200, {'Content-Type' => 'text/plain', 'Content-Length' => '1'}, "Hello, World!"] }
28 response = Rack::ContentLength.new(app).call({})
29 response[1]['Content-Length'].should.equal '1'
30 end
31
7a0476b @rtomayko Rack::ContentLength tweaks ...
rtomayko authored
32 specify "does not set Content-Length on 304 responses" do
33 app = lambda { |env| [304, {'Content-Type' => 'text/plain'}, []] }
34 response = Rack::ContentLength.new(app).call({})
35 response[1]['Content-Length'].should.equal nil
36 end
37
38 specify "does not set Content-Length when Transfer-Encoding is chunked" do
39 app = lambda { |env| [200, {'Transfer-Encoding' => 'chunked'}, []] }
5b60d28 @josh Add ContentLength middleware
josh authored
40 response = Rack::ContentLength.new(app).call({})
41 response[1]['Content-Length'].should.equal nil
42 end
43 end
Something went wrong with that request. Please try again.