eac-rack 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +18 -0
- data/KNOWN-ISSUES +21 -0
- data/README +399 -0
- data/bin/rackup +4 -0
- data/contrib/rack_logo.svg +111 -0
- data/example/lobster.ru +4 -0
- data/example/protectedlobster.rb +14 -0
- data/example/protectedlobster.ru +8 -0
- data/lib/rack.rb +92 -0
- data/lib/rack/adapter/camping.rb +22 -0
- data/lib/rack/auth/abstract/handler.rb +37 -0
- data/lib/rack/auth/abstract/request.rb +37 -0
- data/lib/rack/auth/basic.rb +58 -0
- data/lib/rack/auth/digest/md5.rb +124 -0
- data/lib/rack/auth/digest/nonce.rb +51 -0
- data/lib/rack/auth/digest/params.rb +55 -0
- data/lib/rack/auth/digest/request.rb +40 -0
- data/lib/rack/builder.rb +80 -0
- data/lib/rack/cascade.rb +41 -0
- data/lib/rack/chunked.rb +49 -0
- data/lib/rack/commonlogger.rb +49 -0
- data/lib/rack/conditionalget.rb +47 -0
- data/lib/rack/config.rb +15 -0
- data/lib/rack/content_length.rb +29 -0
- data/lib/rack/content_type.rb +23 -0
- data/lib/rack/deflater.rb +96 -0
- data/lib/rack/directory.rb +157 -0
- data/lib/rack/etag.rb +23 -0
- data/lib/rack/file.rb +90 -0
- data/lib/rack/handler.rb +88 -0
- data/lib/rack/handler/cgi.rb +61 -0
- data/lib/rack/handler/evented_mongrel.rb +8 -0
- data/lib/rack/handler/fastcgi.rb +89 -0
- data/lib/rack/handler/lsws.rb +63 -0
- data/lib/rack/handler/mongrel.rb +90 -0
- data/lib/rack/handler/scgi.rb +62 -0
- data/lib/rack/handler/swiftiplied_mongrel.rb +8 -0
- data/lib/rack/handler/thin.rb +18 -0
- data/lib/rack/handler/webrick.rb +69 -0
- data/lib/rack/head.rb +19 -0
- data/lib/rack/lint.rb +575 -0
- data/lib/rack/lobster.rb +65 -0
- data/lib/rack/lock.rb +16 -0
- data/lib/rack/logger.rb +20 -0
- data/lib/rack/methodoverride.rb +27 -0
- data/lib/rack/mime.rb +206 -0
- data/lib/rack/mock.rb +189 -0
- data/lib/rack/nulllogger.rb +18 -0
- data/lib/rack/recursive.rb +57 -0
- data/lib/rack/reloader.rb +109 -0
- data/lib/rack/request.rb +271 -0
- data/lib/rack/response.rb +149 -0
- data/lib/rack/rewindable_input.rb +100 -0
- data/lib/rack/runtime.rb +27 -0
- data/lib/rack/sendfile.rb +142 -0
- data/lib/rack/server.rb +212 -0
- data/lib/rack/session/abstract/id.rb +140 -0
- data/lib/rack/session/cookie.rb +90 -0
- data/lib/rack/session/memcache.rb +119 -0
- data/lib/rack/session/pool.rb +100 -0
- data/lib/rack/showexceptions.rb +349 -0
- data/lib/rack/showstatus.rb +106 -0
- data/lib/rack/static.rb +38 -0
- data/lib/rack/urlmap.rb +56 -0
- data/lib/rack/utils.rb +614 -0
- data/rack.gemspec +38 -0
- data/test/spec_rack_auth_basic.rb +73 -0
- data/test/spec_rack_auth_digest.rb +226 -0
- data/test/spec_rack_builder.rb +84 -0
- data/test/spec_rack_camping.rb +51 -0
- data/test/spec_rack_cascade.rb +48 -0
- data/test/spec_rack_cgi.rb +89 -0
- data/test/spec_rack_chunked.rb +62 -0
- data/test/spec_rack_commonlogger.rb +61 -0
- data/test/spec_rack_conditionalget.rb +41 -0
- data/test/spec_rack_config.rb +24 -0
- data/test/spec_rack_content_length.rb +43 -0
- data/test/spec_rack_content_type.rb +30 -0
- data/test/spec_rack_deflater.rb +127 -0
- data/test/spec_rack_directory.rb +61 -0
- data/test/spec_rack_etag.rb +17 -0
- data/test/spec_rack_fastcgi.rb +89 -0
- data/test/spec_rack_file.rb +75 -0
- data/test/spec_rack_handler.rb +43 -0
- data/test/spec_rack_head.rb +30 -0
- data/test/spec_rack_lint.rb +528 -0
- data/test/spec_rack_lobster.rb +45 -0
- data/test/spec_rack_lock.rb +38 -0
- data/test/spec_rack_logger.rb +21 -0
- data/test/spec_rack_methodoverride.rb +60 -0
- data/test/spec_rack_mock.rb +243 -0
- data/test/spec_rack_mongrel.rb +189 -0
- data/test/spec_rack_nulllogger.rb +13 -0
- data/test/spec_rack_recursive.rb +77 -0
- data/test/spec_rack_request.rb +545 -0
- data/test/spec_rack_response.rb +221 -0
- data/test/spec_rack_rewindable_input.rb +118 -0
- data/test/spec_rack_runtime.rb +35 -0
- data/test/spec_rack_sendfile.rb +86 -0
- data/test/spec_rack_session_cookie.rb +73 -0
- data/test/spec_rack_session_memcache.rb +273 -0
- data/test/spec_rack_session_pool.rb +172 -0
- data/test/spec_rack_showexceptions.rb +21 -0
- data/test/spec_rack_showstatus.rb +72 -0
- data/test/spec_rack_static.rb +37 -0
- data/test/spec_rack_thin.rb +91 -0
- data/test/spec_rack_urlmap.rb +215 -0
- data/test/spec_rack_utils.rb +554 -0
- data/test/spec_rack_webrick.rb +130 -0
- data/test/spec_rackup.rb +154 -0
- metadata +311 -0
@@ -0,0 +1,221 @@
|
|
1
|
+
require 'test/spec'
|
2
|
+
require 'set'
|
3
|
+
|
4
|
+
require 'rack/response'
|
5
|
+
|
6
|
+
context "Rack::Response" do
|
7
|
+
specify "has sensible default values" do
|
8
|
+
response = Rack::Response.new
|
9
|
+
status, header, body = response.finish
|
10
|
+
status.should.equal 200
|
11
|
+
header.should.equal "Content-Type" => "text/html"
|
12
|
+
body.each { |part|
|
13
|
+
part.should.equal ""
|
14
|
+
}
|
15
|
+
|
16
|
+
response = Rack::Response.new
|
17
|
+
status, header, body = *response
|
18
|
+
status.should.equal 200
|
19
|
+
header.should.equal "Content-Type" => "text/html"
|
20
|
+
body.each { |part|
|
21
|
+
part.should.equal ""
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
specify "can be written to" do
|
26
|
+
response = Rack::Response.new
|
27
|
+
|
28
|
+
status, header, body = response.finish do
|
29
|
+
response.write "foo"
|
30
|
+
response.write "bar"
|
31
|
+
response.write "baz"
|
32
|
+
end
|
33
|
+
|
34
|
+
parts = []
|
35
|
+
body.each { |part| parts << part }
|
36
|
+
|
37
|
+
parts.should.equal ["foo", "bar", "baz"]
|
38
|
+
end
|
39
|
+
|
40
|
+
specify "can set and read headers" do
|
41
|
+
response = Rack::Response.new
|
42
|
+
response["Content-Type"].should.equal "text/html"
|
43
|
+
response["Content-Type"] = "text/plain"
|
44
|
+
response["Content-Type"].should.equal "text/plain"
|
45
|
+
end
|
46
|
+
|
47
|
+
specify "can set cookies" do
|
48
|
+
response = Rack::Response.new
|
49
|
+
|
50
|
+
response.set_cookie "foo", "bar"
|
51
|
+
response["Set-Cookie"].should.equal "foo=bar"
|
52
|
+
response.set_cookie "foo2", "bar2"
|
53
|
+
response["Set-Cookie"].should.equal ["foo=bar", "foo2=bar2"]
|
54
|
+
response.set_cookie "foo3", "bar3"
|
55
|
+
response["Set-Cookie"].should.equal ["foo=bar", "foo2=bar2", "foo3=bar3"]
|
56
|
+
end
|
57
|
+
|
58
|
+
specify "formats the Cookie expiration date accordingly to RFC 2109" do
|
59
|
+
response = Rack::Response.new
|
60
|
+
|
61
|
+
response.set_cookie "foo", {:value => "bar", :expires => Time.now+10}
|
62
|
+
response["Set-Cookie"].should.match(
|
63
|
+
/expires=..., \d\d-...-\d\d\d\d \d\d:\d\d:\d\d .../)
|
64
|
+
end
|
65
|
+
|
66
|
+
specify "can set secure cookies" do
|
67
|
+
response = Rack::Response.new
|
68
|
+
response.set_cookie "foo", {:value => "bar", :secure => true}
|
69
|
+
response["Set-Cookie"].should.equal "foo=bar; secure"
|
70
|
+
end
|
71
|
+
|
72
|
+
specify "can set http only cookies" do
|
73
|
+
response = Rack::Response.new
|
74
|
+
response.set_cookie "foo", {:value => "bar", :httponly => true}
|
75
|
+
response["Set-Cookie"].should.equal "foo=bar; HttpOnly"
|
76
|
+
end
|
77
|
+
|
78
|
+
specify "can delete cookies" do
|
79
|
+
response = Rack::Response.new
|
80
|
+
response.set_cookie "foo", "bar"
|
81
|
+
response.set_cookie "foo2", "bar2"
|
82
|
+
response.delete_cookie "foo"
|
83
|
+
response["Set-Cookie"].should.equal ["foo2=bar2",
|
84
|
+
"foo=; expires=Thu, 01-Jan-1970 00:00:00 GMT"]
|
85
|
+
end
|
86
|
+
|
87
|
+
specify "can do redirects" do
|
88
|
+
response = Rack::Response.new
|
89
|
+
response.redirect "/foo"
|
90
|
+
status, header, body = response.finish
|
91
|
+
|
92
|
+
status.should.equal 302
|
93
|
+
header["Location"].should.equal "/foo"
|
94
|
+
|
95
|
+
response = Rack::Response.new
|
96
|
+
response.redirect "/foo", 307
|
97
|
+
status, header, body = response.finish
|
98
|
+
|
99
|
+
status.should.equal 307
|
100
|
+
end
|
101
|
+
|
102
|
+
specify "has a useful constructor" do
|
103
|
+
r = Rack::Response.new("foo")
|
104
|
+
status, header, body = r.finish
|
105
|
+
str = ""; body.each { |part| str << part }
|
106
|
+
str.should.equal "foo"
|
107
|
+
|
108
|
+
r = Rack::Response.new(["foo", "bar"])
|
109
|
+
status, header, body = r.finish
|
110
|
+
str = ""; body.each { |part| str << part }
|
111
|
+
str.should.equal "foobar"
|
112
|
+
|
113
|
+
r = Rack::Response.new(["foo", "bar"].to_set)
|
114
|
+
r.write "foo"
|
115
|
+
status, header, body = r.finish
|
116
|
+
str = ""; body.each { |part| str << part }
|
117
|
+
str.should.equal "foobarfoo"
|
118
|
+
|
119
|
+
r = Rack::Response.new([], 500)
|
120
|
+
r.status.should.equal 500
|
121
|
+
|
122
|
+
r = Rack::Response.new([], "200 OK")
|
123
|
+
r.status.should.equal 200
|
124
|
+
end
|
125
|
+
|
126
|
+
specify "has a constructor that can take a block" do
|
127
|
+
r = Rack::Response.new { |res|
|
128
|
+
res.status = 404
|
129
|
+
res.write "foo"
|
130
|
+
}
|
131
|
+
status, header, body = r.finish
|
132
|
+
str = ""; body.each { |part| str << part }
|
133
|
+
str.should.equal "foo"
|
134
|
+
status.should.equal 404
|
135
|
+
end
|
136
|
+
|
137
|
+
specify "doesn't return invalid responses" do
|
138
|
+
r = Rack::Response.new(["foo", "bar"], 204)
|
139
|
+
status, header, body = r.finish
|
140
|
+
str = ""; body.each { |part| str << part }
|
141
|
+
str.should.be.empty
|
142
|
+
header["Content-Type"].should.equal nil
|
143
|
+
|
144
|
+
lambda {
|
145
|
+
Rack::Response.new(Object.new)
|
146
|
+
}.should.raise(TypeError).
|
147
|
+
message.should =~ /stringable or iterable required/
|
148
|
+
end
|
149
|
+
|
150
|
+
specify "knows if it's empty" do
|
151
|
+
r = Rack::Response.new
|
152
|
+
r.should.be.empty
|
153
|
+
r.write "foo"
|
154
|
+
r.should.not.be.empty
|
155
|
+
|
156
|
+
r = Rack::Response.new
|
157
|
+
r.should.be.empty
|
158
|
+
r.finish
|
159
|
+
r.should.be.empty
|
160
|
+
|
161
|
+
r = Rack::Response.new
|
162
|
+
r.should.be.empty
|
163
|
+
r.finish { }
|
164
|
+
r.should.not.be.empty
|
165
|
+
end
|
166
|
+
|
167
|
+
specify "should provide access to the HTTP status" do
|
168
|
+
res = Rack::Response.new
|
169
|
+
res.status = 200
|
170
|
+
res.should.be.successful
|
171
|
+
res.should.be.ok
|
172
|
+
|
173
|
+
res.status = 404
|
174
|
+
res.should.not.be.successful
|
175
|
+
res.should.be.client_error
|
176
|
+
res.should.be.not_found
|
177
|
+
|
178
|
+
res.status = 501
|
179
|
+
res.should.not.be.successful
|
180
|
+
res.should.be.server_error
|
181
|
+
|
182
|
+
res.status = 307
|
183
|
+
res.should.be.redirect
|
184
|
+
end
|
185
|
+
|
186
|
+
specify "should provide access to the HTTP headers" do
|
187
|
+
res = Rack::Response.new
|
188
|
+
res["Content-Type"] = "text/yaml"
|
189
|
+
|
190
|
+
res.should.include "Content-Type"
|
191
|
+
res.headers["Content-Type"].should.equal "text/yaml"
|
192
|
+
res["Content-Type"].should.equal "text/yaml"
|
193
|
+
res.content_type.should.equal "text/yaml"
|
194
|
+
res.content_length.should.be.nil
|
195
|
+
res.location.should.be.nil
|
196
|
+
end
|
197
|
+
|
198
|
+
specify "does not add or change Content-Length when #finish()ing" do
|
199
|
+
res = Rack::Response.new
|
200
|
+
res.status = 200
|
201
|
+
res.finish
|
202
|
+
res.headers["Content-Length"].should.be.nil
|
203
|
+
|
204
|
+
res = Rack::Response.new
|
205
|
+
res.status = 200
|
206
|
+
res.headers["Content-Length"] = "10"
|
207
|
+
res.finish
|
208
|
+
res.headers["Content-Length"].should.equal "10"
|
209
|
+
end
|
210
|
+
|
211
|
+
specify "updates Content-Length when body appended to using #write" do
|
212
|
+
res = Rack::Response.new
|
213
|
+
res.status = 200
|
214
|
+
res.headers["Content-Length"].should.be.nil
|
215
|
+
res.write "Hi"
|
216
|
+
res.headers["Content-Length"].should.equal "2"
|
217
|
+
res.write " there"
|
218
|
+
res.headers["Content-Length"].should.equal "8"
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'test/spec'
|
2
|
+
require 'stringio'
|
3
|
+
require 'rack/rewindable_input'
|
4
|
+
|
5
|
+
shared_context "a rewindable IO object" do
|
6
|
+
setup do
|
7
|
+
@rio = Rack::RewindableInput.new(@io)
|
8
|
+
end
|
9
|
+
|
10
|
+
teardown do
|
11
|
+
@rio.close
|
12
|
+
end
|
13
|
+
|
14
|
+
specify "should be able to handle to read()" do
|
15
|
+
@rio.read.should.equal "hello world"
|
16
|
+
end
|
17
|
+
|
18
|
+
specify "should be able to handle to read(nil)" do
|
19
|
+
@rio.read(nil).should.equal "hello world"
|
20
|
+
end
|
21
|
+
|
22
|
+
specify "should be able to handle to read(length)" do
|
23
|
+
@rio.read(1).should.equal "h"
|
24
|
+
end
|
25
|
+
|
26
|
+
specify "should be able to handle to read(length, buffer)" do
|
27
|
+
buffer = ""
|
28
|
+
result = @rio.read(1, buffer)
|
29
|
+
result.should.equal "h"
|
30
|
+
result.object_id.should.equal buffer.object_id
|
31
|
+
end
|
32
|
+
|
33
|
+
specify "should be able to handle to read(nil, buffer)" do
|
34
|
+
buffer = ""
|
35
|
+
result = @rio.read(nil, buffer)
|
36
|
+
result.should.equal "hello world"
|
37
|
+
result.object_id.should.equal buffer.object_id
|
38
|
+
end
|
39
|
+
|
40
|
+
specify "should rewind to the beginning when #rewind is called" do
|
41
|
+
@rio.read(1)
|
42
|
+
@rio.rewind
|
43
|
+
@rio.read.should.equal "hello world"
|
44
|
+
end
|
45
|
+
|
46
|
+
specify "should be able to handle gets" do
|
47
|
+
@rio.gets.should == "hello world"
|
48
|
+
end
|
49
|
+
|
50
|
+
specify "should be able to handle each" do
|
51
|
+
array = []
|
52
|
+
@rio.each do |data|
|
53
|
+
array << data
|
54
|
+
end
|
55
|
+
array.should.equal(["hello world"])
|
56
|
+
end
|
57
|
+
|
58
|
+
specify "should not buffer into a Tempfile if no data has been read yet" do
|
59
|
+
@rio.instance_variable_get(:@rewindable_io).should.be.nil
|
60
|
+
end
|
61
|
+
|
62
|
+
specify "should buffer into a Tempfile when data has been consumed for the first time" do
|
63
|
+
@rio.read(1)
|
64
|
+
tempfile = @rio.instance_variable_get(:@rewindable_io)
|
65
|
+
tempfile.should.not.be.nil
|
66
|
+
@rio.read(1)
|
67
|
+
tempfile2 = @rio.instance_variable_get(:@rewindable_io)
|
68
|
+
tempfile2.should.equal tempfile
|
69
|
+
end
|
70
|
+
|
71
|
+
specify "should close the underlying tempfile upon calling #close" do
|
72
|
+
@rio.read(1)
|
73
|
+
tempfile = @rio.instance_variable_get(:@rewindable_io)
|
74
|
+
@rio.close
|
75
|
+
tempfile.should.be.closed
|
76
|
+
end
|
77
|
+
|
78
|
+
specify "should be possibel to call #close when no data has been buffered yet" do
|
79
|
+
@rio.close
|
80
|
+
end
|
81
|
+
|
82
|
+
specify "should be possible to call #close multiple times" do
|
83
|
+
@rio.close
|
84
|
+
@rio.close
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "Rack::RewindableInput" do
|
89
|
+
context "given an IO object that is already rewindable" do
|
90
|
+
setup do
|
91
|
+
@io = StringIO.new("hello world")
|
92
|
+
end
|
93
|
+
|
94
|
+
it_should_behave_like "a rewindable IO object"
|
95
|
+
end
|
96
|
+
|
97
|
+
context "given an IO object that is not rewindable" do
|
98
|
+
setup do
|
99
|
+
@io = StringIO.new("hello world")
|
100
|
+
@io.instance_eval do
|
101
|
+
undef :rewind
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
it_should_behave_like "a rewindable IO object"
|
106
|
+
end
|
107
|
+
|
108
|
+
context "given an IO object whose rewind method raises Errno::ESPIPE" do
|
109
|
+
setup do
|
110
|
+
@io = StringIO.new("hello world")
|
111
|
+
def @io.rewind
|
112
|
+
raise Errno::ESPIPE, "You can't rewind this!"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
it_should_behave_like "a rewindable IO object"
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'test/spec'
|
2
|
+
require 'rack/mock'
|
3
|
+
require 'rack/runtime'
|
4
|
+
|
5
|
+
context "Rack::Runtime" do
|
6
|
+
specify "sets X-Runtime is none is set" do
|
7
|
+
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] }
|
8
|
+
response = Rack::Runtime.new(app).call({})
|
9
|
+
response[1]['X-Runtime'].should =~ /[\d\.]+/
|
10
|
+
end
|
11
|
+
|
12
|
+
specify "does not set the X-Runtime if it is already set" do
|
13
|
+
app = lambda { |env| [200, {'Content-Type' => 'text/plain', "X-Runtime" => "foobar"}, "Hello, World!"] }
|
14
|
+
response = Rack::Runtime.new(app).call({})
|
15
|
+
response[1]['X-Runtime'].should == "foobar"
|
16
|
+
end
|
17
|
+
|
18
|
+
specify "should allow a suffix to be set" do
|
19
|
+
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] }
|
20
|
+
response = Rack::Runtime.new(app, "Test").call({})
|
21
|
+
response[1]['X-Runtime-Test'].should =~ /[\d\.]+/
|
22
|
+
end
|
23
|
+
|
24
|
+
specify "should allow multiple timers to be set" do
|
25
|
+
app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, "Hello, World!"] }
|
26
|
+
runtime1 = Rack::Runtime.new(app, "App")
|
27
|
+
runtime2 = Rack::Runtime.new(runtime1, "All")
|
28
|
+
response = runtime2.call({})
|
29
|
+
|
30
|
+
response[1]['X-Runtime-App'].should =~ /[\d\.]+/
|
31
|
+
response[1]['X-Runtime-All'].should =~ /[\d\.]+/
|
32
|
+
|
33
|
+
Float(response[1]['X-Runtime-All']).should > Float(response[1]['X-Runtime-App'])
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'test/spec'
|
2
|
+
require 'rack/mock'
|
3
|
+
require 'rack/sendfile'
|
4
|
+
|
5
|
+
context "Rack::File" do
|
6
|
+
specify "should respond to #to_path" do
|
7
|
+
Rack::File.new(Dir.pwd).should.respond_to :to_path
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context "Rack::Sendfile" do
|
12
|
+
def sendfile_body
|
13
|
+
res = ['Hello World']
|
14
|
+
def res.to_path ; "/tmp/hello.txt" ; end
|
15
|
+
res
|
16
|
+
end
|
17
|
+
|
18
|
+
def simple_app(body=sendfile_body)
|
19
|
+
lambda { |env| [200, {'Content-Type' => 'text/plain'}, body] }
|
20
|
+
end
|
21
|
+
|
22
|
+
def sendfile_app(body=sendfile_body)
|
23
|
+
Rack::Sendfile.new(simple_app(body))
|
24
|
+
end
|
25
|
+
|
26
|
+
setup do
|
27
|
+
@request = Rack::MockRequest.new(sendfile_app)
|
28
|
+
end
|
29
|
+
|
30
|
+
def request(headers={})
|
31
|
+
yield @request.get('/', headers)
|
32
|
+
end
|
33
|
+
|
34
|
+
specify "does nothing when no X-Sendfile-Type header present" do
|
35
|
+
request do |response|
|
36
|
+
response.should.be.ok
|
37
|
+
response.body.should.equal 'Hello World'
|
38
|
+
response.headers.should.not.include 'X-Sendfile'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
specify "sets X-Sendfile response header and discards body" do
|
43
|
+
request 'HTTP_X_SENDFILE_TYPE' => 'X-Sendfile' do |response|
|
44
|
+
response.should.be.ok
|
45
|
+
response.body.should.be.empty
|
46
|
+
response.headers['X-Sendfile'].should.equal '/tmp/hello.txt'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
specify "sets X-Lighttpd-Send-File response header and discards body" do
|
51
|
+
request 'HTTP_X_SENDFILE_TYPE' => 'X-Lighttpd-Send-File' do |response|
|
52
|
+
response.should.be.ok
|
53
|
+
response.body.should.be.empty
|
54
|
+
response.headers['X-Lighttpd-Send-File'].should.equal '/tmp/hello.txt'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
specify "sets X-Accel-Redirect response header and discards body" do
|
59
|
+
headers = {
|
60
|
+
'HTTP_X_SENDFILE_TYPE' => 'X-Accel-Redirect',
|
61
|
+
'HTTP_X_ACCEL_MAPPING' => '/tmp/=/foo/bar/'
|
62
|
+
}
|
63
|
+
request headers do |response|
|
64
|
+
response.should.be.ok
|
65
|
+
response.body.should.be.empty
|
66
|
+
response.headers['X-Accel-Redirect'].should.equal '/foo/bar/hello.txt'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
specify 'writes to rack.error when no X-Accel-Mapping is specified' do
|
71
|
+
request 'HTTP_X_SENDFILE_TYPE' => 'X-Accel-Redirect' do |response|
|
72
|
+
response.should.be.ok
|
73
|
+
response.body.should.equal 'Hello World'
|
74
|
+
response.headers.should.not.include 'X-Accel-Redirect'
|
75
|
+
response.errors.should.include 'X-Accel-Mapping'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
specify 'does nothing when body does not respond to #to_path' do
|
80
|
+
@request = Rack::MockRequest.new(sendfile_app(['Not a file...']))
|
81
|
+
request 'HTTP_X_SENDFILE_TYPE' => 'X-Sendfile' do |response|
|
82
|
+
response.body.should.equal 'Not a file...'
|
83
|
+
response.headers.should.not.include 'X-Sendfile'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|