rack 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. data/README +23 -26
  2. data/SPEC +3 -3
  3. data/lib/rack/auth/digest/params.rb +1 -1
  4. data/lib/rack/content_length.rb +1 -1
  5. data/lib/rack/etag.rb +15 -6
  6. data/lib/rack/file.rb +3 -1
  7. data/lib/rack/handler/cgi.rb +8 -7
  8. data/lib/rack/handler/fastcgi.rb +1 -1
  9. data/lib/rack/handler/lsws.rb +1 -1
  10. data/lib/rack/handler/mongrel.rb +1 -1
  11. data/lib/rack/handler/scgi.rb +1 -4
  12. data/lib/rack/handler/webrick.rb +10 -6
  13. data/lib/rack/lint.rb +29 -37
  14. data/lib/rack/mime.rb +2 -0
  15. data/lib/rack/mock.rb +2 -1
  16. data/lib/rack/recursive.rb +4 -0
  17. data/lib/rack/request.rb +8 -6
  18. data/lib/rack/response.rb +1 -0
  19. data/lib/rack/rewindable_input.rb +13 -10
  20. data/lib/rack/sendfile.rb +8 -6
  21. data/lib/rack/server.rb +66 -7
  22. data/lib/rack/session/memcache.rb +1 -1
  23. data/lib/rack/urlmap.rb +6 -7
  24. data/lib/rack/utils.rb +64 -22
  25. data/lib/rack.rb +1 -12
  26. data/rack.gemspec +6 -6
  27. data/spec/cgi/lighttpd.conf +25 -0
  28. data/spec/cgi/rackup_stub.rb +6 -0
  29. data/spec/cgi/sample_rackup.ru +5 -0
  30. data/spec/cgi/test +9 -0
  31. data/spec/cgi/test.fcgi +8 -0
  32. data/spec/cgi/test.ru +5 -0
  33. data/spec/multipart/bad_robots +259 -0
  34. data/spec/multipart/binary +0 -0
  35. data/spec/multipart/empty +10 -0
  36. data/spec/multipart/fail_16384_nofile +814 -0
  37. data/spec/multipart/file1.txt +1 -0
  38. data/spec/multipart/filename_and_modification_param +7 -0
  39. data/spec/multipart/filename_with_escaped_quotes +6 -0
  40. data/spec/multipart/filename_with_escaped_quotes_and_modification_param +7 -0
  41. data/spec/multipart/filename_with_percent_escaped_quotes +6 -0
  42. data/spec/multipart/filename_with_unescaped_quotes +6 -0
  43. data/spec/multipart/ie +6 -0
  44. data/spec/multipart/nested +10 -0
  45. data/spec/multipart/none +9 -0
  46. data/spec/multipart/semicolon +6 -0
  47. data/spec/multipart/text +10 -0
  48. data/spec/rackup/config.ru +31 -0
  49. data/{test/spec_rack_auth_basic.rb → spec/spec_auth_basic.rb} +11 -14
  50. data/{test/spec_rack_auth_digest.rb → spec/spec_auth_digest.rb} +18 -21
  51. data/{test/spec_rack_builder.rb → spec/spec_builder.rb} +49 -10
  52. data/{test/spec_rack_cascade.rb → spec/spec_cascade.rb} +7 -10
  53. data/{test/spec_rack_cgi.rb → spec/spec_cgi.rb} +34 -32
  54. data/{test/spec_rack_chunked.rb → spec/spec_chunked.rb} +8 -10
  55. data/{test/spec_rack_commonlogger.rb → spec/spec_commonlogger.rb} +10 -15
  56. data/{test/spec_rack_conditionalget.rb → spec/spec_conditionalget.rb} +5 -7
  57. data/{test/spec_rack_config.rb → spec/spec_config.rb} +6 -7
  58. data/{test/spec_rack_content_length.rb → spec/spec_content_length.rb} +7 -8
  59. data/{test/spec_rack_content_type.rb → spec/spec_content_type.rb} +5 -6
  60. data/{test/spec_rack_deflater.rb → spec/spec_deflater.rb} +11 -13
  61. data/{test/spec_rack_directory.rb → spec/spec_directory.rb} +6 -10
  62. data/{test/spec_rack_etag.rb → spec/spec_etag.rb} +3 -5
  63. data/{test/spec_rack_fastcgi.rb → spec/spec_fastcgi.rb} +36 -29
  64. data/{test/spec_rack_file.rb → spec/spec_file.rb} +9 -13
  65. data/{test/spec_rack_handler.rb → spec/spec_handler.rb} +10 -12
  66. data/{test/spec_rack_head.rb → spec/spec_head.rb} +3 -3
  67. data/{test/spec_rack_lint.rb → spec/spec_lint.rb} +19 -32
  68. data/{test/spec_rack_lobster.rb → spec/spec_lobster.rb} +9 -11
  69. data/{test/spec_rack_lock.rb → spec/spec_lock.rb} +15 -17
  70. data/{test/spec_rack_logger.rb → spec/spec_logger.rb} +6 -7
  71. data/{test/spec_rack_methodoverride.rb → spec/spec_methodoverride.rb} +15 -17
  72. data/{test/spec_rack_mock.rb → spec/spec_mock.rb} +30 -32
  73. data/{test/spec_rack_mongrel.rb → spec/spec_mongrel.rb} +40 -46
  74. data/{test/spec_rack_nulllogger.rb → spec/spec_nulllogger.rb} +4 -5
  75. data/{test/spec_rack_recursive.rb → spec/spec_recursive.rb} +28 -36
  76. data/{test/spec_rack_request.rb → spec/spec_request.rb} +84 -49
  77. data/{test/spec_rack_response.rb → spec/spec_response.rb} +48 -29
  78. data/spec/spec_rewindable_input.rb +118 -0
  79. data/{test/spec_rack_runtime.rb → spec/spec_runtime.rb} +15 -11
  80. data/{test/spec_rack_sendfile.rb → spec/spec_sendfile.rb} +11 -14
  81. data/{test/spec_rack_session_cookie.rb → spec/spec_session_cookie.rb} +15 -18
  82. data/{test/spec_rack_session_memcache.rb → spec/spec_session_memcache.rb} +32 -26
  83. data/{test/spec_rack_session_pool.rb → spec/spec_session_pool.rb} +36 -31
  84. data/spec/spec_showexceptions.rb +23 -0
  85. data/spec/spec_showstatus.rb +79 -0
  86. data/{test/spec_rack_static.rb → spec/spec_static.rb} +5 -9
  87. data/{test/spec_rack_thin.rb → spec/spec_thin.rb} +30 -35
  88. data/{test/spec_rack_urlmap.rb → spec/spec_urlmap.rb} +6 -8
  89. data/{test/spec_rack_utils.rb → spec/spec_utils.rb} +136 -71
  90. data/{test/spec_rack_webrick.rb → spec/spec_webrick.rb} +28 -36
  91. data/spec/testrequest.rb +77 -0
  92. data/spec/unregistered_handler/rack/handler/unregistered.rb +7 -0
  93. data/spec/unregistered_handler/rack/handler/unregistered_long_one.rb +7 -0
  94. metadata +206 -124
  95. data/RDOX +0 -0
  96. data/lib/rack/adapter/camping.rb +0 -22
  97. data/test/spec_rack_camping.rb +0 -51
  98. data/test/spec_rack_rewindable_input.rb +0 -118
  99. data/test/spec_rack_showexceptions.rb +0 -21
  100. data/test/spec_rack_showstatus.rb +0 -72
  101. data/test/spec_rackup.rb +0 -154
@@ -1,118 +0,0 @@
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
@@ -1,21 +0,0 @@
1
- require 'test/spec'
2
-
3
- require 'rack/showexceptions'
4
- require 'rack/mock'
5
-
6
- context "Rack::ShowExceptions" do
7
- specify "catches exceptions" do
8
- res = nil
9
- req = Rack::MockRequest.new(Rack::ShowExceptions.new(lambda { |env|
10
- raise RuntimeError
11
- }))
12
- lambda {
13
- res = req.get("/")
14
- }.should.not.raise
15
- res.should.be.a.server_error
16
- res.status.should.equal 500
17
-
18
- res.should =~ /RuntimeError/
19
- res.should =~ /ShowExceptions/
20
- end
21
- end
@@ -1,72 +0,0 @@
1
- require 'test/spec'
2
-
3
- require 'rack/showstatus'
4
- require 'rack/mock'
5
-
6
- context "Rack::ShowStatus" do
7
- specify "should provide a default status message" do
8
- req = Rack::MockRequest.new(Rack::ShowStatus.new(lambda { |env|
9
- [404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
10
- }))
11
-
12
- res = req.get("/", :lint => true)
13
- res.should.be.not_found
14
- res.should.be.not.empty
15
-
16
- res["Content-Type"].should.equal("text/html")
17
- res.should =~ /404/
18
- res.should =~ /Not Found/
19
- end
20
-
21
- specify "should let the app provide additional information" do
22
- req = Rack::MockRequest.new(Rack::ShowStatus.new(lambda { |env|
23
- env["rack.showstatus.detail"] = "gone too meta."
24
- [404, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
25
- }))
26
-
27
- res = req.get("/", :lint => true)
28
- res.should.be.not_found
29
- res.should.be.not.empty
30
-
31
- res["Content-Type"].should.equal("text/html")
32
- res.should =~ /404/
33
- res.should =~ /Not Found/
34
- res.should =~ /too meta/
35
- end
36
-
37
- specify "should not replace existing messages" do
38
- req = Rack::MockRequest.new(Rack::ShowStatus.new(lambda { |env|
39
- [404, {"Content-Type" => "text/plain", "Content-Length" => "4"}, ["foo!"]]
40
- }))
41
- res = req.get("/", :lint => true)
42
- res.should.be.not_found
43
-
44
- res.body.should == "foo!"
45
- end
46
-
47
- specify "should pass on original headers" do
48
- headers = {"WWW-Authenticate" => "Basic blah"}
49
-
50
- req = Rack::MockRequest.new(Rack::ShowStatus.new(lambda { |env| [401, headers, []] }))
51
- res = req.get("/", :lint => true)
52
-
53
- res["WWW-Authenticate"].should.equal("Basic blah")
54
- end
55
-
56
- specify "should replace existing messages if there is detail" do
57
- req = Rack::MockRequest.new(Rack::ShowStatus.new(lambda { |env|
58
- env["rack.showstatus.detail"] = "gone too meta."
59
- [404, {"Content-Type" => "text/plain", "Content-Length" => "4"}, ["foo!"]]
60
- }))
61
-
62
- res = req.get("/", :lint => true)
63
- res.should.be.not_found
64
- res.should.be.not.empty
65
-
66
- res["Content-Type"].should.equal("text/html")
67
- res["Content-Length"].should.not.equal("4")
68
- res.should =~ /404/
69
- res.should =~ /too meta/
70
- res.body.should.not =~ /foo/
71
- end
72
- end
data/test/spec_rackup.rb DELETED
@@ -1,154 +0,0 @@
1
- require 'test/spec'
2
- require 'testrequest'
3
- require 'rack/server'
4
- require 'open3'
5
-
6
- begin
7
- require "mongrel"
8
-
9
- context "rackup" do
10
- include TestRequest::Helpers
11
-
12
- def run_rackup(*args)
13
- options = args.last.is_a?(Hash) ? args.pop : {}
14
- flags = args.first
15
- @host = options[:host] || "0.0.0.0"
16
- @port = options[:port] || 9292
17
-
18
- Dir.chdir("#{root}/test/rackup") do
19
- @in, @rackup, @err = Open3.popen3("#{Gem.ruby} -S #{rackup} #{flags}")
20
- end
21
-
22
- return if options[:port] == false
23
-
24
- # Wait until the server is available
25
- begin
26
- GET("/")
27
- rescue
28
- sleep 0.05
29
- retry
30
- end
31
- end
32
-
33
- def output
34
- @rackup.read
35
- end
36
-
37
- after do
38
- # This doesn't actually return a response, so we rescue
39
- GET "/die" rescue nil
40
-
41
- Dir["#{root}/**/*.pid"].each do |file|
42
- File.delete(file)
43
- end
44
-
45
- File.delete("#{root}/log_output") if File.exist?("#{root}/log_output")
46
- end
47
-
48
- specify "rackup" do
49
- run_rackup
50
- response["PATH_INFO"].should.equal '/'
51
- response["test.$DEBUG"].should.be false
52
- response["test.$EVAL"].should.be nil
53
- response["test.$VERBOSE"].should.be false
54
- response["test.Ping"].should.be nil
55
- response["SERVER_SOFTWARE"].should.not =~ /webrick/
56
- end
57
-
58
- specify "rackup --help" do
59
- run_rackup "--help", :port => false
60
- output.should.match /--port/
61
- end
62
-
63
- specify "rackup --port" do
64
- run_rackup "--port 9000", :port => 9000
65
- response["SERVER_PORT"].should.equal "9000"
66
- end
67
-
68
- specify "rackup --debug" do
69
- run_rackup "--debug"
70
- response["test.$DEBUG"].should.be true
71
- end
72
-
73
- specify "rackup --eval" do
74
- run_rackup %{--eval "BUKKIT = 'BUKKIT'"}
75
- response["test.$EVAL"].should.equal "BUKKIT"
76
- end
77
-
78
- specify "rackup --warn" do
79
- run_rackup %{--warn}
80
- response["test.$VERBOSE"].should.be true
81
- end
82
-
83
- specify "rackup --include" do
84
- run_rackup %{--include /foo/bar}
85
- response["test.$LOAD_PATH"].should.include "/foo/bar"
86
- end
87
-
88
- specify "rackup --require" do
89
- run_rackup %{--require ping}
90
- response["test.Ping"].should.equal "constant"
91
- end
92
-
93
- specify "rackup --server" do
94
- run_rackup %{--server webrick}
95
- response["SERVER_SOFTWARE"].should =~ /webrick/i
96
- end
97
-
98
- specify "rackup --host" do
99
- run_rackup %{--host 127.0.0.1}, :host => "127.0.0.1"
100
- response["REMOTE_ADDR"].should.equal "127.0.0.1"
101
- end
102
-
103
- specify "rackup --daemonize --pid" do
104
- run_rackup %{--daemonize --pid testing.pid}
105
- status.should.be 200
106
- @rackup.should.be.eof?
107
- Dir["#{root}/**/testing.pid"].should.not.be.empty?
108
- end
109
-
110
- specify "rackup --pid" do
111
- run_rackup %{--pid testing.pid}
112
- status.should.be 200
113
- Dir["#{root}/**/testing.pid"].should.not.be.empty?
114
- end
115
-
116
- specify "rackup --version" do
117
- run_rackup %{--version}, :port => false
118
- output.should =~ /1.0/
119
- end
120
-
121
- specify "rackup --env development includes lint" do
122
- run_rackup
123
- GET("/broken_lint")
124
- status.should.be 500
125
- end
126
-
127
- specify "rackup --env deployment does not include lint" do
128
- run_rackup %{--env deployment}
129
- GET("/broken_lint")
130
- status.should.be 200
131
- end
132
-
133
- specify "rackup --env none does not include lint" do
134
- run_rackup %{--env none}
135
- GET("/broken_lint")
136
- status.should.be 200
137
- end
138
-
139
- specify "rackup --env deployment does log" do
140
- run_rackup %{--env deployment}
141
- log = File.read(response["test.stderr"])
142
- log.should.be.empty?
143
- end
144
-
145
- specify "rackup --env none does not log" do
146
- run_rackup %{--env none}
147
- GET("/")
148
- log = File.read(response["test.stderr"])
149
- log.should.be.empty?
150
- end
151
- end
152
- rescue LoadError
153
- $stderr.puts "Skipping rackup --server tests (mongrel is required). `gem install thin` and try again."
154
- end