rack 0.1.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.

Files changed (54) hide show
  1. data/AUTHORS +3 -0
  2. data/COPYING +18 -0
  3. data/KNOWN-ISSUES +18 -0
  4. data/RDOX +144 -0
  5. data/README +154 -0
  6. data/Rakefile +174 -0
  7. data/SPEC +132 -0
  8. data/bin/rackup +148 -0
  9. data/contrib/rack_logo.svg +111 -0
  10. data/example/lobster.ru +4 -0
  11. data/lib/rack.rb +67 -0
  12. data/lib/rack/adapter/camping.rb +16 -0
  13. data/lib/rack/adapter/rails.rb +65 -0
  14. data/lib/rack/builder.rb +52 -0
  15. data/lib/rack/cascade.rb +26 -0
  16. data/lib/rack/commonlogger.rb +56 -0
  17. data/lib/rack/file.rb +108 -0
  18. data/lib/rack/handler/cgi.rb +57 -0
  19. data/lib/rack/handler/fastcgi.rb +81 -0
  20. data/lib/rack/handler/mongrel.rb +57 -0
  21. data/lib/rack/handler/webrick.rb +56 -0
  22. data/lib/rack/lint.rb +394 -0
  23. data/lib/rack/lobster.rb +65 -0
  24. data/lib/rack/mock.rb +183 -0
  25. data/lib/rack/recursive.rb +57 -0
  26. data/lib/rack/reloader.rb +64 -0
  27. data/lib/rack/request.rb +112 -0
  28. data/lib/rack/response.rb +114 -0
  29. data/lib/rack/showexceptions.rb +344 -0
  30. data/lib/rack/urlmap.rb +50 -0
  31. data/lib/rack/utils.rb +176 -0
  32. data/test/cgi/lighttpd.conf +20 -0
  33. data/test/cgi/test +9 -0
  34. data/test/cgi/test.fcgi +9 -0
  35. data/test/cgi/test.ru +7 -0
  36. data/test/spec_rack_camping.rb +44 -0
  37. data/test/spec_rack_cascade.rb +35 -0
  38. data/test/spec_rack_cgi.rb +82 -0
  39. data/test/spec_rack_commonlogger.rb +32 -0
  40. data/test/spec_rack_fastcgi.rb +82 -0
  41. data/test/spec_rack_file.rb +32 -0
  42. data/test/spec_rack_lint.rb +317 -0
  43. data/test/spec_rack_lobster.rb +45 -0
  44. data/test/spec_rack_mock.rb +150 -0
  45. data/test/spec_rack_mongrel.rb +87 -0
  46. data/test/spec_rack_recursive.rb +77 -0
  47. data/test/spec_rack_request.rb +219 -0
  48. data/test/spec_rack_response.rb +110 -0
  49. data/test/spec_rack_showexceptions.rb +21 -0
  50. data/test/spec_rack_urlmap.rb +140 -0
  51. data/test/spec_rack_utils.rb +57 -0
  52. data/test/spec_rack_webrick.rb +89 -0
  53. data/test/testrequest.rb +43 -0
  54. metadata +117 -0
data/AUTHORS ADDED
@@ -0,0 +1,3 @@
1
+ * Christian Neukirchen <chneukirchen@gmail.com>
2
+ * Rails adapter: Christoffer Sawicki <christoffer.sawicki@gmail.com>
3
+ * Official Logo: Armin Ronacher
data/COPYING ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2007 Christian Neukirchen <purl.org/net/chneukirchen>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to
5
+ deal in the Software without restriction, including without limitation the
6
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ sell copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,18 @@
1
+ = Known issues with Rack and Web servers
2
+
3
+ * Lighttpd sets wrong SCRIPT_NAME and PATH_INFO if you mount your
4
+ FastCGI app at "/". This can be fixed by using this middleware:
5
+
6
+ class LighttpdScriptNameFix
7
+ def initialize(app)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ env["PATH_INFO"] = env["SCRIPT_NAME"].to_s + env["PATH_INFO"].to_s
13
+ env["SCRIPT_NAME"] = ""
14
+ @app.call(env)
15
+ end
16
+ end
17
+
18
+ Of course, use this only when your app runs at "/".
data/RDOX ADDED
@@ -0,0 +1,144 @@
1
+
2
+ == Rack::Adapter::Camping
3
+ * works with GET
4
+ * works with POST
5
+
6
+ == Rack::Cascade
7
+ * should dispatch onward on 404 by default
8
+ * should dispatch onward on whatever is passed
9
+ * should fail if empty
10
+
11
+ == Rack::Handler::CGI
12
+ * should respond
13
+ * should be a lighttpd
14
+ * should have rack headers
15
+ * should have CGI headers on GET
16
+ * should have CGI headers on POST
17
+ * should support HTTP auth
18
+ * should set status
19
+
20
+ == Rack::CommonLogger
21
+ * should log to rack.errors by default
22
+ * should log to anything with <<
23
+
24
+ == Rack::Handler::FastCGI
25
+ * should respond
26
+ * should be a lighttpd
27
+ * should have rack headers
28
+ * should have CGI headers on GET
29
+ * should have CGI headers on POST
30
+ * should support HTTP auth
31
+ * should set status
32
+
33
+ == Rack::File
34
+ * serves files
35
+ * does not allow directory traversal
36
+ * 404s if it can't find the file
37
+
38
+ == Rack::Lint
39
+ * passes valid request
40
+ * notices fatal errors
41
+ * notices environment errors
42
+ * notices input errors
43
+ * notices error errors
44
+ * notices status errors
45
+ * notices header errors
46
+ * notices content-type errors
47
+ * notices body errors
48
+ * notices input handling errors
49
+ * notices error handling errors
50
+
51
+ == Rack::Lobster::LambdaLobster
52
+ * should be a single lambda
53
+ * should look like a lobster
54
+ * should be flippable
55
+
56
+ == Rack::Lobster
57
+ * should look like a lobster
58
+ * should be flippable
59
+ * should provide crashing for testing purposes
60
+
61
+ == Rack::MockRequest
62
+ * should return a MockResponse
63
+ * should be able to only return the environment
64
+ * should provide sensible defaults
65
+ * should allow GET/POST/PUT/DELETE
66
+ * should allow posting
67
+ * should use all parts of an URL
68
+ * should behave valid according to the Rack spec
69
+
70
+ == Rack::MockResponse
71
+ * should provide access to the HTTP status
72
+ * should provide access to the HTTP headers
73
+ * should provide access to the HTTP body
74
+ * should provide access to the Rack errors
75
+ * should optionally make Rack errors fatal
76
+
77
+ == Rack::Handler::Mongrel
78
+ * should respond
79
+ * should be a Mongrel
80
+ * should have rack headers
81
+ * should have CGI headers on GET
82
+ * should have CGI headers on POST
83
+ * should support HTTP auth
84
+ * should set status
85
+
86
+ == Rack::Recursive
87
+ * should allow for subrequests
88
+ * should raise error on requests not below the app
89
+ * should support forwarding
90
+
91
+ == Rack::Request
92
+ * wraps the rack variables
93
+ * can figure out the correct host
94
+ * can parse the query string
95
+ * can parse POST data
96
+ * can cache, but invalidates the cache
97
+ * can figure out if called via XHR
98
+ * can parse cookies
99
+ * provides setters
100
+ * provides the original env
101
+ * can restore the URL
102
+ * can parse multipart form data
103
+ * can parse big multipart form data
104
+ * can detect invalid multipart form data
105
+
106
+ == Rack::Response
107
+ * has sensible default values
108
+ * can be written to
109
+ * can set and read headers
110
+ * can set cookies
111
+ * can delete cookies
112
+ * has a useful constructor
113
+ * has a constructor that can take a block
114
+ * doesn't return invalid responses
115
+
116
+ == Rack::ShowExceptions
117
+ * catches exceptions
118
+
119
+ == Rack::URLMap
120
+ * dispatches paths correctly
121
+ * dispatches hosts correctly
122
+ * should be nestable
123
+ * should route root apps correctly
124
+
125
+ == Rack::Utils
126
+ * should escape correctly
127
+ * should unescape correctly
128
+ * should parse queries correctly
129
+
130
+ == Rack::Utils::HeaderHash
131
+ * should capitalize on all accesses
132
+ * should capitalize correctly
133
+ * should be converted to real Hash
134
+
135
+ == Rack::Handler::WEBrick
136
+ * should respond
137
+ * should be a WEBrick
138
+ * should have rack headers
139
+ * should have CGI headers on GET
140
+ * should have CGI headers on POST
141
+ * should support HTTP auth
142
+ * should set status
143
+
144
+ 102 specifications (428 requirements), 0 failures
data/README ADDED
@@ -0,0 +1,154 @@
1
+ = Rack, a modular Ruby webserver interface
2
+
3
+ Rack provides minimal, modular and adaptable interface for developing
4
+ web applications in Ruby. By wrapping HTTP requests and responses in
5
+ the simplest way possible, it unifies and distills the API for web
6
+ servers, web frameworks, and software in between (the so-called
7
+ middleware) into a single method call.
8
+
9
+ The exact details of this are described in the Rack specification,
10
+ which all Rack applications should conform to.
11
+
12
+ == Supported web servers
13
+
14
+ The included *handlers* connect all kinds of web servers to Rack:
15
+ * Mongrel
16
+ * WEBrick
17
+ * FCGI
18
+ * CGI
19
+
20
+ Any valid Rack app will run the same on all these handlers, without
21
+ changing anything.
22
+
23
+ == Supported web frameworks
24
+
25
+ The included *adapters* connect Rack with existing Ruby web frameworks:
26
+ * Camping
27
+ * Rails (alpha)
28
+ * more to come soon, ...
29
+
30
+ These frameworks include Rack adapters in their distributions:
31
+ * Ramaze
32
+ * Maveric
33
+ * Racktools::SimpleApplication
34
+
35
+ == Available middleware
36
+
37
+ Between the server and the framework, Rack can be customized to your
38
+ applications needs using middleware, for example:
39
+ * Rack::URLMap, to route to multiple applications inside the same process.
40
+ * Rack::CommonLogger, for creating Apache-style logfiles.
41
+ * Rack::ShowException, for catching unhandled exceptions and
42
+ presenting them in a nice and helpful way with clickable backtrace.
43
+ * Rack::File, for serving static files.
44
+ * ...
45
+
46
+ All these components use the same interface, which is described in
47
+ detail in the Rack specification. You can choose to use them exactly
48
+ in the way you want.
49
+
50
+ == Convenience
51
+
52
+ If you want to develop outside of existing frameworks, implement your
53
+ own ones, or develop middleware, Rack provides many helpers to create
54
+ Rack applications quickly and without doing the same web stuff all
55
+ over:
56
+ * Rack::Request, which also provides query string parsing and
57
+ multipart handling.
58
+ * Rack::Response, for convenient generation of HTTP replies and
59
+ cookie handling.
60
+ * Rack::MockRequest and Rack::MockResponse for efficient and quick
61
+ testing of Rack application without real HTTP round-trips.
62
+
63
+ == rackup
64
+
65
+ rackup is a useful tool for running Rack applications, which uses the
66
+ Rack::Builder DSL to configure middleware and build up applications
67
+ easily.
68
+
69
+ rackup automatically figures out the environment it is run in, and
70
+ runs your application as FastCGI, CGI, or standalone with Mongrel or
71
+ WEBrick---all from the same configuration.
72
+
73
+ == Quick start
74
+
75
+ Try the lobster!
76
+
77
+ Either with the embedded WEBrick starter:
78
+
79
+ ruby -Ilib lib/rack/lobster.rb
80
+
81
+ Or with rackup:
82
+
83
+ bin/rackup -Ilib example/lobster.ru
84
+
85
+ By default, the lobster is found at http://localhost:9292.
86
+
87
+ == Installing with RubyGems
88
+
89
+ A Gem of Rack is available. You can install it with:
90
+
91
+ gem install rack
92
+
93
+ I also provide a local mirror of the gems (and development snapshots)
94
+ at my site:
95
+
96
+ gem install rack --source http://chneukirchen.org/releases/gems
97
+
98
+ == History
99
+
100
+ * March 3rd, 2007: First public release 0.1.
101
+
102
+ == Contact
103
+
104
+ Please mail bugs, suggestions and patches to
105
+ <mailto:chneukirchen@gmail.com>.
106
+
107
+ Darcs repository ("darcs send" is welcome for patches):
108
+ http://chneukirchen.org/repos/rack
109
+
110
+ You are also welcome to join the #rack channel on irc.freenode.net.
111
+
112
+ == Thanks to
113
+
114
+ * Michael Fellinger, for the helpful discussion.
115
+ * Christoffer Sawicki, for the Rails adapter.
116
+ * Armin Ronacher, for the logo and racktools.
117
+ * Alexander Kellett for testing the Gem and reviewing the announce.
118
+ * Marcus Rückert, for help with configuring and debugging lighttpd.
119
+ * The WSGI team for the well-done and documented work they've done and
120
+ Rack builds up on.
121
+
122
+ == Copyright
123
+
124
+ Copyright (C) 2007 Christian Neukirchen <http://purl.org/net/chneukirchen>
125
+
126
+ Permission is hereby granted, free of charge, to any person obtaining a copy
127
+ of this software and associated documentation files (the "Software"), to
128
+ deal in the Software without restriction, including without limitation the
129
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
130
+ sell copies of the Software, and to permit persons to whom the Software is
131
+ furnished to do so, subject to the following conditions:
132
+
133
+ The above copyright notice and this permission notice shall be included in
134
+ all copies or substantial portions of the Software.
135
+
136
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
137
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
138
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
139
+ THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
140
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
141
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
142
+
143
+ == Links
144
+
145
+ Rack:: <http://rack.rubyforge.org/>
146
+ Rack's Rubyforge project:: <http://rubyforge.org/projects/rack>
147
+
148
+ Camping:: <http://camping.rubyforge.org/>
149
+ Ramaze:: <http://ramaze.rubyforge.org/>
150
+ Maveric:: <http://maveric.rubyforge.org/>
151
+ racktools:: <http://lucumr.pocoo.org/trac/repos/racktools/>
152
+
153
+ Christian Neukirchen:: <http://chneukirchen.org/>
154
+
@@ -0,0 +1,174 @@
1
+ # Rakefile for Rack. -*-ruby-*-
2
+ require 'rake/rdoctask'
3
+ require 'rake/testtask'
4
+
5
+
6
+ desc "Run all the tests"
7
+ task :default => [:test]
8
+
9
+ desc "Do predistribution stuff"
10
+ task :predist => [:chmod, :changelog, :rdoc]
11
+
12
+
13
+ desc "Make an archive as .tar.gz"
14
+ task :dist => :fulltest do
15
+ system "export DARCS_REPO=#{File.expand_path "."}; " +
16
+ "darcs dist -d rack-#{get_darcs_tree_version}"
17
+ end
18
+
19
+ # Helper to retrieve the "revision number" of the darcs tree.
20
+ def get_darcs_tree_version
21
+ unless File.directory? "_darcs"
22
+ require 'rack'
23
+ return Rack.version
24
+ end
25
+
26
+ changes = `darcs changes`
27
+ count = 0
28
+ tag = "0.0"
29
+
30
+ changes.each("\n\n") { |change|
31
+ head, title, desc = change.split("\n", 3)
32
+
33
+ if title =~ /^ \*/
34
+ # Normal change.
35
+ count += 1
36
+ elsif title =~ /tagged (.*)/
37
+ # Tag. We look for these.
38
+ tag = $1
39
+ break
40
+ else
41
+ warn "Unparsable change: #{change}"
42
+ end
43
+ }
44
+
45
+ tag + "." + count.to_s
46
+ end
47
+
48
+ def manifest
49
+ `darcs query manifest`.split("\n").map { |f| f.gsub(/\A\.\//, '') }
50
+ end
51
+
52
+
53
+ desc "Make binaries executable"
54
+ task :chmod do
55
+ Dir["bin/*"].each { |binary| File.chmod(0775, binary) }
56
+ Dir["test/cgi/test*"].each { |binary| File.chmod(0775, binary) }
57
+ end
58
+
59
+ desc "Generate a ChangeLog"
60
+ task :changelog do
61
+ system "darcs changes --repo=#{ENV["DARCS_REPO"] || "."} >ChangeLog"
62
+ end
63
+
64
+
65
+ desc "Generate RDox"
66
+ task "RDOX" do
67
+ system "specrb -Ilib:test -a --rdox >RDOX"
68
+ end
69
+
70
+ desc "Generate Rack Specification"
71
+ task "SPEC" do
72
+ File.open("SPEC", "wb") { |file|
73
+ IO.foreach("lib/rack/lint.rb") { |line|
74
+ if line =~ /## (.*)/
75
+ file.puts $1
76
+ end
77
+ }
78
+ }
79
+ end
80
+
81
+ desc "Run all the fast tests"
82
+ task :test do
83
+ system "specrb -Ilib:test -w #{ENV['TEST'] || '-a'} #{ENV['TESTOPTS'] || '-t "^(?!Rack::Handler|Rack::Adapter)"'}"
84
+ end
85
+
86
+ desc "Run all the tests"
87
+ task :fulltest do
88
+ system "specrb -Ilib:test -w #{ENV['TEST'] || '-a'} #{ENV['TESTOPTS']}"
89
+ end
90
+
91
+ begin
92
+ $" << "sources" if defined? FromSrc
93
+ require 'rubygems'
94
+
95
+ require 'rake'
96
+ require 'rake/clean'
97
+ require 'rake/packagetask'
98
+ require 'rake/gempackagetask'
99
+ require 'fileutils'
100
+ rescue LoadError
101
+ # Too bad.
102
+ else
103
+ spec = Gem::Specification.new do |s|
104
+ s.name = "rack"
105
+ s.version = get_darcs_tree_version
106
+ s.platform = Gem::Platform::RUBY
107
+ s.summary = "a modular Ruby webserver interface"
108
+
109
+ s.description = <<-EOF
110
+ Rack provides minimal, modular and adaptable interface for developing
111
+ web applications in Ruby. By wrapping HTTP requests and responses in
112
+ the simplest way possible, it unifies and distills the API for web
113
+ servers, web frameworks, and software in between (the so-called
114
+ middleware) into a single method call.
115
+
116
+ Also see http://rack.rubyforge.org.
117
+ EOF
118
+
119
+ s.files = manifest + %w(SPEC RDOX)
120
+ s.bindir = 'bin'
121
+ s.executables << 'rackup'
122
+ s.require_path = 'lib'
123
+ s.has_rdoc = true
124
+ s.extra_rdoc_files = ['README', 'SPEC', 'RDOX', 'KNOWN-ISSUES']
125
+ s.test_files = Dir['test/{test,spec}_*.rb']
126
+
127
+ s.author = 'Christian Neukirchen'
128
+ s.email = 'chneukirchen@gmail.com'
129
+ s.homepage = 'http://rack.rubyforge.org'
130
+ s.rubyforge_project = 'rack'
131
+ end
132
+
133
+ Rake::GemPackageTask.new(spec) do |p|
134
+ p.gem_spec = spec
135
+ p.need_tar = false
136
+ p.need_zip = false
137
+ end
138
+ end
139
+
140
+ desc "Generate RDoc documentation"
141
+ Rake::RDocTask.new(:rdoc) do |rdoc|
142
+ rdoc.options << '--line-numbers' << '--inline-source' <<
143
+ '--main' << 'README' <<
144
+ '--title' << 'Rack Documentation' <<
145
+ '--charset' << 'utf-8'
146
+ rdoc.rdoc_dir = "doc"
147
+ rdoc.rdoc_files.include 'README'
148
+ rdoc.rdoc_files.include 'KNOWN-ISSUES'
149
+ rdoc.rdoc_files.include 'SPEC'
150
+ rdoc.rdoc_files.include 'RDOX'
151
+ rdoc.rdoc_files.include('lib/rack.rb')
152
+ rdoc.rdoc_files.include('lib/rack/*.rb')
153
+ rdoc.rdoc_files.include('lib/rack/*/*.rb')
154
+ end
155
+ task :rdoc => ["SPEC", "RDOX"]
156
+
157
+ task :pushsite => [:rdoc] do
158
+ system "rsync -avz doc/ chneukirchen@rack.rubyforge.org:/var/www/gforge-projects/rack/doc/"
159
+ system "rsync -avz site/ chneukirchen@rack.rubyforge.org:/var/www/gforge-projects/rack/"
160
+ end
161
+
162
+ begin
163
+ require 'rcov/rcovtask'
164
+
165
+ Rcov::RcovTask.new do |t|
166
+ t.test_files = FileList['test/{spec,test}_*.rb']
167
+ t.verbose = true # uncomment to see the executed command
168
+ t.rcov_opts = ["--text-report",
169
+ "-Ilib:test",
170
+ "--include-file", "^lib,^test",
171
+ "--exclude-only", "^/usr,^/home/.*/src,active_"]
172
+ end
173
+ rescue LoadError
174
+ end