rack 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of rack might be problematic. Click here for more details.
- data/AUTHORS +2 -0
- data/RDOX +46 -1
- data/README +19 -4
- data/Rakefile +9 -8
- data/bin/rackup +2 -0
- data/example/protectedlobster.rb +14 -0
- data/lib/rack.rb +19 -0
- data/lib/rack/adapter/camping.rb +6 -0
- data/lib/rack/auth/abstract/handler.rb +28 -0
- data/lib/rack/auth/abstract/request.rb +39 -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 +52 -0
- data/lib/rack/auth/digest/params.rb +55 -0
- data/lib/rack/auth/digest/request.rb +40 -0
- data/lib/rack/commonlogger.rb +1 -1
- data/lib/rack/file.rb +1 -1
- data/lib/rack/handler/cgi.rb +7 -7
- data/lib/rack/handler/fastcgi.rb +1 -1
- data/lib/rack/handler/mongrel.rb +8 -7
- data/lib/rack/handler/webrick.rb +7 -6
- data/lib/rack/lint.rb +3 -3
- data/lib/rack/lobster.rb +4 -4
- data/lib/rack/mock.rb +9 -33
- data/lib/rack/recursive.rb +1 -1
- data/lib/rack/reloader.rb +1 -1
- data/lib/rack/request.rb +32 -9
- data/lib/rack/response.rb +54 -8
- data/lib/rack/session/cookie.rb +73 -0
- data/lib/rack/showexceptions.rb +2 -2
- data/lib/rack/showstatus.rb +103 -0
- data/lib/rack/static.rb +38 -0
- data/lib/rack/urlmap.rb +1 -1
- data/lib/rack/utils.rb +45 -3
- data/test/spec_rack_auth_basic.rb +68 -0
- data/test/spec_rack_auth_digest.rb +167 -0
- data/test/spec_rack_camping.rb +3 -0
- data/test/spec_rack_mock.rb +2 -0
- data/test/spec_rack_mongrel.rb +12 -0
- data/test/spec_rack_request.rb +60 -0
- data/test/spec_rack_response.rb +50 -1
- data/test/spec_rack_session_cookie.rb +49 -0
- data/test/spec_rack_showstatus.rb +71 -0
- data/test/spec_rack_static.rb +37 -0
- data/test/spec_rack_urlmap.rb +1 -7
- data/test/spec_rack_webrick.rb +17 -0
- metadata +23 -3
- data/lib/rack/adapter/rails.rb +0 -65
@@ -0,0 +1,71 @@
|
|
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"}, []]
|
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"}, []]
|
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"}, ["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"}, ["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.should =~ /404/
|
68
|
+
res.should =~ /too meta/
|
69
|
+
res.body.should.not =~ /foo/
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test/spec'
|
2
|
+
|
3
|
+
require 'rack/static'
|
4
|
+
require 'rack/mock'
|
5
|
+
|
6
|
+
class DummyApp
|
7
|
+
def call(env)
|
8
|
+
[200, {}, "Hello World"]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "Rack::Static" do
|
13
|
+
root = File.expand_path(File.dirname(__FILE__))
|
14
|
+
OPTIONS = {:urls => ["/cgi"], :root => root}
|
15
|
+
|
16
|
+
setup do
|
17
|
+
@request = Rack::MockRequest.new(Rack::Static.new(DummyApp.new, OPTIONS))
|
18
|
+
end
|
19
|
+
|
20
|
+
specify "serves files" do
|
21
|
+
res = @request.get("/cgi/test")
|
22
|
+
res.should.be.ok
|
23
|
+
res.body.should =~ /ruby/
|
24
|
+
end
|
25
|
+
|
26
|
+
specify "404s if url root is known but it can't find the file" do
|
27
|
+
res = @request.get("/cgi/foo")
|
28
|
+
res.should.be.not_found
|
29
|
+
end
|
30
|
+
|
31
|
+
specify "calls down the chain if url root is not known" do
|
32
|
+
res = @request.get("/something/else")
|
33
|
+
res.should.be.ok
|
34
|
+
res.body.should == "Hello World"
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/test/spec_rack_urlmap.rb
CHANGED
@@ -17,14 +17,8 @@ context "Rack::URLMap" do
|
|
17
17
|
{ "Content-Type" => "text/plain",
|
18
18
|
"X-Position" => "/bar",
|
19
19
|
"X-PathInfo" => env["PATH_INFO"],
|
20
|
-
}, [""]]},
|
21
|
-
|
22
|
-
"/foo/bar" => lambda { |env|
|
23
|
-
[200,
|
24
|
-
{ "Content-Type" => "text/plain",
|
25
|
-
"X-Position" => "/foo/bar",
|
26
|
-
"X-PathInfo" => env["PATH_INFO"],
|
27
20
|
}, [""]]}
|
21
|
+
|
28
22
|
)
|
29
23
|
|
30
24
|
|
data/test/spec_rack_webrick.rb
CHANGED
@@ -83,6 +83,23 @@ context "Rack::Handler::WEBrick" do
|
|
83
83
|
response["rack.url_scheme"].should.equal "http"
|
84
84
|
end
|
85
85
|
|
86
|
+
specify "should provide a .run" do
|
87
|
+
block_ran = false
|
88
|
+
catch(:done) {
|
89
|
+
Rack::Handler::WEBrick.run(lambda {},
|
90
|
+
{:Port => 9210,
|
91
|
+
:Logger => WEBrick::Log.new(nil, WEBrick::BasicLog::WARN),
|
92
|
+
:AccessLog => []}) { |server|
|
93
|
+
block_ran = true
|
94
|
+
server.should.be.kind_of WEBrick::HTTPServer
|
95
|
+
@s = server
|
96
|
+
throw :done
|
97
|
+
}
|
98
|
+
}
|
99
|
+
block_ran.should.be true
|
100
|
+
@s.shutdown
|
101
|
+
end
|
102
|
+
|
86
103
|
teardown do
|
87
104
|
@server.shutdown
|
88
105
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0.8
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rack
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.2.0
|
7
|
+
date: 2007-05-16 00:00:00 +02:00
|
8
8
|
summary: a modular Ruby webserver interface
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -34,9 +34,16 @@ files:
|
|
34
34
|
- contrib/rack_logo.svg
|
35
35
|
- COPYING
|
36
36
|
- example/lobster.ru
|
37
|
+
- example/protectedlobster.rb
|
37
38
|
- KNOWN-ISSUES
|
38
39
|
- lib/rack/adapter/camping.rb
|
39
|
-
- lib/rack/
|
40
|
+
- lib/rack/auth/abstract/handler.rb
|
41
|
+
- lib/rack/auth/abstract/request.rb
|
42
|
+
- lib/rack/auth/basic.rb
|
43
|
+
- lib/rack/auth/digest/md5.rb
|
44
|
+
- lib/rack/auth/digest/nonce.rb
|
45
|
+
- lib/rack/auth/digest/params.rb
|
46
|
+
- lib/rack/auth/digest/request.rb
|
40
47
|
- lib/rack/builder.rb
|
41
48
|
- lib/rack/cascade.rb
|
42
49
|
- lib/rack/commonlogger.rb
|
@@ -52,7 +59,10 @@ files:
|
|
52
59
|
- lib/rack/reloader.rb
|
53
60
|
- lib/rack/request.rb
|
54
61
|
- lib/rack/response.rb
|
62
|
+
- lib/rack/session/cookie.rb
|
55
63
|
- lib/rack/showexceptions.rb
|
64
|
+
- lib/rack/showstatus.rb
|
65
|
+
- lib/rack/static.rb
|
56
66
|
- lib/rack/urlmap.rb
|
57
67
|
- lib/rack/utils.rb
|
58
68
|
- lib/rack.rb
|
@@ -62,6 +72,8 @@ files:
|
|
62
72
|
- test/cgi/test
|
63
73
|
- test/cgi/test.fcgi
|
64
74
|
- test/cgi/test.ru
|
75
|
+
- test/spec_rack_auth_basic.rb
|
76
|
+
- test/spec_rack_auth_digest.rb
|
65
77
|
- test/spec_rack_camping.rb
|
66
78
|
- test/spec_rack_cascade.rb
|
67
79
|
- test/spec_rack_cgi.rb
|
@@ -75,7 +87,10 @@ files:
|
|
75
87
|
- test/spec_rack_recursive.rb
|
76
88
|
- test/spec_rack_request.rb
|
77
89
|
- test/spec_rack_response.rb
|
90
|
+
- test/spec_rack_session_cookie.rb
|
78
91
|
- test/spec_rack_showexceptions.rb
|
92
|
+
- test/spec_rack_showstatus.rb
|
93
|
+
- test/spec_rack_static.rb
|
79
94
|
- test/spec_rack_urlmap.rb
|
80
95
|
- test/spec_rack_utils.rb
|
81
96
|
- test/spec_rack_webrick.rb
|
@@ -83,6 +98,8 @@ files:
|
|
83
98
|
- SPEC
|
84
99
|
- RDOX
|
85
100
|
test_files:
|
101
|
+
- test/spec_rack_auth_basic.rb
|
102
|
+
- test/spec_rack_auth_digest.rb
|
86
103
|
- test/spec_rack_camping.rb
|
87
104
|
- test/spec_rack_cascade.rb
|
88
105
|
- test/spec_rack_cgi.rb
|
@@ -96,7 +113,10 @@ test_files:
|
|
96
113
|
- test/spec_rack_recursive.rb
|
97
114
|
- test/spec_rack_request.rb
|
98
115
|
- test/spec_rack_response.rb
|
116
|
+
- test/spec_rack_session_cookie.rb
|
99
117
|
- test/spec_rack_showexceptions.rb
|
118
|
+
- test/spec_rack_showstatus.rb
|
119
|
+
- test/spec_rack_static.rb
|
100
120
|
- test/spec_rack_urlmap.rb
|
101
121
|
- test/spec_rack_utils.rb
|
102
122
|
- test/spec_rack_webrick.rb
|
data/lib/rack/adapter/rails.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
unless defined? RAILS_ROOT
|
2
|
-
raise "Rails' environment has to be loaded before using Rack::Adapter::Rails"
|
3
|
-
end
|
4
|
-
|
5
|
-
require "dispatcher"
|
6
|
-
|
7
|
-
module Rack
|
8
|
-
module Adapter
|
9
|
-
# TODO: Extract this
|
10
|
-
class Rails < Cascade
|
11
|
-
def initialize
|
12
|
-
file = Rack::File.new(::File.join(RAILS_ROOT, "public"))
|
13
|
-
dispatcher = RailsDispatcher.new
|
14
|
-
|
15
|
-
super([file, dispatcher])
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class RailsDispatcher
|
20
|
-
def call(env)
|
21
|
-
response = dispatch(CGIStub.new(env))
|
22
|
-
headers = response.headers
|
23
|
-
status = headers.delete("Status")
|
24
|
-
|
25
|
-
[ status, headers, response.body ]
|
26
|
-
end
|
27
|
-
|
28
|
-
protected
|
29
|
-
|
30
|
-
def dispatch(cgi)
|
31
|
-
session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS
|
32
|
-
|
33
|
-
request = ActionController::CgiRequest.new(cgi, session_options)
|
34
|
-
response = ActionController::CgiResponse.new(cgi)
|
35
|
-
|
36
|
-
Dispatcher.send(:prepare_application)
|
37
|
-
|
38
|
-
controller = ActionController::Routing::Routes.recognize(request)
|
39
|
-
controller.process(request, response)
|
40
|
-
|
41
|
-
return response
|
42
|
-
end
|
43
|
-
|
44
|
-
class RailsDispatcher::CGIStub
|
45
|
-
def initialize(env)
|
46
|
-
@request = Request.new(env)
|
47
|
-
end
|
48
|
-
|
49
|
-
def env_table() @request.env end
|
50
|
-
def params() @request.params end
|
51
|
-
def cookies() @request.cookies end
|
52
|
-
def query_string() @request.query_string end
|
53
|
-
|
54
|
-
def [](key)
|
55
|
-
# FIXME: This is probably just wrong
|
56
|
-
@request.env[key] || @request.cookies[key]
|
57
|
-
end
|
58
|
-
|
59
|
-
def key?(key)
|
60
|
-
self[key] ? true : false
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|