kastner-rack 0.3.171

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/AUTHORS +8 -0
  2. data/COPYING +18 -0
  3. data/KNOWN-ISSUES +18 -0
  4. data/README +273 -0
  5. data/Rakefile +185 -0
  6. data/bin/rackup +172 -0
  7. data/contrib/rack_logo.svg +111 -0
  8. data/example/lobster.ru +4 -0
  9. data/example/protectedlobster.rb +14 -0
  10. data/example/protectedlobster.ru +8 -0
  11. data/lib/rack.rb +85 -0
  12. data/lib/rack/adapter/camping.rb +22 -0
  13. data/lib/rack/auth/abstract/handler.rb +28 -0
  14. data/lib/rack/auth/abstract/request.rb +37 -0
  15. data/lib/rack/auth/basic.rb +58 -0
  16. data/lib/rack/auth/digest/md5.rb +124 -0
  17. data/lib/rack/auth/digest/nonce.rb +51 -0
  18. data/lib/rack/auth/digest/params.rb +55 -0
  19. data/lib/rack/auth/digest/request.rb +40 -0
  20. data/lib/rack/auth/openid.rb +437 -0
  21. data/lib/rack/builder.rb +67 -0
  22. data/lib/rack/cascade.rb +36 -0
  23. data/lib/rack/commonlogger.rb +61 -0
  24. data/lib/rack/conditionalget.rb +42 -0
  25. data/lib/rack/deflater.rb +63 -0
  26. data/lib/rack/directory.rb +149 -0
  27. data/lib/rack/file.rb +84 -0
  28. data/lib/rack/handler.rb +46 -0
  29. data/lib/rack/handler/cgi.rb +57 -0
  30. data/lib/rack/handler/evented_mongrel.rb +8 -0
  31. data/lib/rack/handler/fastcgi.rb +86 -0
  32. data/lib/rack/handler/lsws.rb +52 -0
  33. data/lib/rack/handler/mongrel.rb +78 -0
  34. data/lib/rack/handler/scgi.rb +57 -0
  35. data/lib/rack/handler/swiftiplied_mongrel.rb +8 -0
  36. data/lib/rack/handler/webrick.rb +61 -0
  37. data/lib/rack/head.rb +19 -0
  38. data/lib/rack/lint.rb +463 -0
  39. data/lib/rack/lobster.rb +65 -0
  40. data/lib/rack/methodoverride.rb +21 -0
  41. data/lib/rack/mime.rb +204 -0
  42. data/lib/rack/mock.rb +160 -0
  43. data/lib/rack/recursive.rb +57 -0
  44. data/lib/rack/reloader.rb +64 -0
  45. data/lib/rack/request.rb +217 -0
  46. data/lib/rack/response.rb +171 -0
  47. data/lib/rack/session/abstract/id.rb +140 -0
  48. data/lib/rack/session/cookie.rb +89 -0
  49. data/lib/rack/session/memcache.rb +97 -0
  50. data/lib/rack/session/pool.rb +73 -0
  51. data/lib/rack/showexceptions.rb +348 -0
  52. data/lib/rack/showstatus.rb +105 -0
  53. data/lib/rack/static.rb +38 -0
  54. data/lib/rack/urlmap.rb +48 -0
  55. data/lib/rack/utils.rb +318 -0
  56. data/rack.gemspec +31 -0
  57. data/test/cgi/lighttpd.conf +20 -0
  58. data/test/cgi/test +9 -0
  59. data/test/cgi/test.fcgi +8 -0
  60. data/test/cgi/test.ru +7 -0
  61. data/test/spec_rack_auth_basic.rb +69 -0
  62. data/test/spec_rack_auth_digest.rb +169 -0
  63. data/test/spec_rack_auth_openid.rb +137 -0
  64. data/test/spec_rack_builder.rb +84 -0
  65. data/test/spec_rack_camping.rb +51 -0
  66. data/test/spec_rack_cascade.rb +50 -0
  67. data/test/spec_rack_cgi.rb +89 -0
  68. data/test/spec_rack_commonlogger.rb +32 -0
  69. data/test/spec_rack_conditionalget.rb +41 -0
  70. data/test/spec_rack_deflater.rb +70 -0
  71. data/test/spec_rack_directory.rb +56 -0
  72. data/test/spec_rack_fastcgi.rb +89 -0
  73. data/test/spec_rack_file.rb +57 -0
  74. data/test/spec_rack_handler.rb +24 -0
  75. data/test/spec_rack_head.rb +30 -0
  76. data/test/spec_rack_lint.rb +371 -0
  77. data/test/spec_rack_lobster.rb +45 -0
  78. data/test/spec_rack_methodoverride.rb +31 -0
  79. data/test/spec_rack_mock.rb +152 -0
  80. data/test/spec_rack_mongrel.rb +170 -0
  81. data/test/spec_rack_recursive.rb +77 -0
  82. data/test/spec_rack_request.rb +426 -0
  83. data/test/spec_rack_response.rb +173 -0
  84. data/test/spec_rack_session_cookie.rb +78 -0
  85. data/test/spec_rack_session_memcache.rb +132 -0
  86. data/test/spec_rack_session_pool.rb +84 -0
  87. data/test/spec_rack_showexceptions.rb +21 -0
  88. data/test/spec_rack_showstatus.rb +72 -0
  89. data/test/spec_rack_static.rb +37 -0
  90. data/test/spec_rack_urlmap.rb +175 -0
  91. data/test/spec_rack_utils.rb +174 -0
  92. data/test/spec_rack_webrick.rb +123 -0
  93. data/test/testrequest.rb +45 -0
  94. metadata +177 -0
@@ -0,0 +1,65 @@
1
+ require 'zlib'
2
+
3
+ require 'rack/request'
4
+ require 'rack/response'
5
+
6
+ module Rack
7
+ # Paste has a Pony, Rack has a Lobster!
8
+ class Lobster
9
+ LobsterString = Zlib::Inflate.inflate("eJx9kEEOwyAMBO99xd7MAcytUhPlJyj2
10
+ P6jy9i4k9EQyGAnBarEXeCBqSkntNXsi/ZCvC48zGQoZKikGrFMZvgS5ZHd+aGWVuWwhVF0
11
+ t1drVmiR42HcWNz5w3QanT+2gIvTVCiE1lm1Y0eU4JGmIIbaKwextKn8rvW+p5PIwFl8ZWJ
12
+ I8jyiTlhTcYXkekJAzTyYN6E08A+dk8voBkAVTJQ==".delete("\n ").unpack("m*")[0])
13
+
14
+ LambdaLobster = lambda { |env|
15
+ if env["QUERY_STRING"].include?("flip")
16
+ lobster = LobsterString.split("\n").
17
+ map { |line| line.ljust(42).reverse }.
18
+ join("\n")
19
+ href = "?"
20
+ else
21
+ lobster = LobsterString
22
+ href = "?flip"
23
+ end
24
+
25
+ content = ["<title>Lobstericious!</title>",
26
+ "<pre>", lobster, "</pre>",
27
+ "<a href='#{href}'>flip!</a>"]
28
+ length = content.inject(0) { |a,e| a+e.size }.to_s
29
+ [200, {"Content-Type" => "text/html", "Content-Length" => length}, content]
30
+ }
31
+
32
+ def call(env)
33
+ req = Request.new(env)
34
+ if req.GET["flip"] == "left"
35
+ lobster = LobsterString.split("\n").
36
+ map { |line| line.ljust(42).reverse }.
37
+ join("\n")
38
+ href = "?flip=right"
39
+ elsif req.GET["flip"] == "crash"
40
+ raise "Lobster crashed"
41
+ else
42
+ lobster = LobsterString
43
+ href = "?flip=left"
44
+ end
45
+
46
+ res = Response.new
47
+ res.write "<title>Lobstericious!</title>"
48
+ res.write "<pre>"
49
+ res.write lobster
50
+ res.write "</pre>"
51
+ res.write "<p><a href='#{href}'>flip!</a></p>"
52
+ res.write "<p><a href='?flip=crash'>crash!</a></p>"
53
+ res.finish
54
+ end
55
+
56
+ end
57
+ end
58
+
59
+ if $0 == __FILE__
60
+ require 'rack'
61
+ require 'rack/showexceptions'
62
+ Rack::Handler::WEBrick.run \
63
+ Rack::ShowExceptions.new(Rack::Lint.new(Rack::Lobster.new)),
64
+ :Port => 9292
65
+ end
@@ -0,0 +1,21 @@
1
+ module Rack
2
+ class MethodOverride
3
+ HTTP_METHODS = %w(GET HEAD PUT POST DELETE OPTIONS)
4
+
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ if env["REQUEST_METHOD"] == "POST"
11
+ req = Request.new(env)
12
+ method = req.POST["_method"].upcase
13
+ if HTTP_METHODS.include?(method)
14
+ env["REQUEST_METHOD"] = method
15
+ end
16
+ end
17
+
18
+ @app.call(env)
19
+ end
20
+ end
21
+ end
data/lib/rack/mime.rb ADDED
@@ -0,0 +1,204 @@
1
+ module Rack
2
+ module Mime
3
+ # Returns String with mime type if found, otherwise use +fallback+.
4
+ # +ext+ should be filename extension in the '.ext' format that
5
+ # File.extname(file) returns.
6
+ # +fallback+ may be any object
7
+ #
8
+ # Also see the documentation for MIME_TYPES
9
+ #
10
+ # Usage:
11
+ # Rack::Utils.mime_type('.foo')
12
+ #
13
+ # This is a shortcut for:
14
+ # Rack::Utils::MIME_TYPES.fetch('.foo', 'application/octet-stream')
15
+
16
+ def mime_type(ext, fallback='application/octet-stream')
17
+ MIME_TYPES.fetch(ext, fallback)
18
+ end
19
+ module_function :mime_type
20
+
21
+ # List of most common mime-types, selected various sources
22
+ # according to their usefulness in a webserving scope for Ruby
23
+ # users.
24
+ #
25
+ # To amend this list with your local mime.types list you can use:
26
+ #
27
+ # require 'webrick/httputils'
28
+ # list = WEBrick::HTTPUtils.load_mime_types('/etc/mime.types')
29
+ # Rack::Utils::MIME_TYPES.merge!(list)
30
+ #
31
+ # To add the list mongrel provides, use:
32
+ #
33
+ # require 'mongrel/handlers'
34
+ # Rack::Utils::MIME_TYPES.merge!(Mongrel::DirHandler::MIME_TYPES)
35
+
36
+ MIME_TYPES = {
37
+ ".3gp" => "video/3gpp",
38
+ ".a" => "application/octet-stream",
39
+ ".ai" => "application/postscript",
40
+ ".aif" => "audio/x-aiff",
41
+ ".aiff" => "audio/x-aiff",
42
+ ".asc" => "application/pgp-signature",
43
+ ".asf" => "video/x-ms-asf",
44
+ ".asm" => "text/x-asm",
45
+ ".asx" => "video/x-ms-asf",
46
+ ".atom" => "application/atom+xml",
47
+ ".au" => "audio/basic",
48
+ ".avi" => "video/x-msvideo",
49
+ ".bat" => "application/x-msdownload",
50
+ ".bin" => "application/octet-stream",
51
+ ".bmp" => "image/bmp",
52
+ ".bz2" => "application/x-bzip2",
53
+ ".c" => "text/x-c",
54
+ ".cab" => "application/vnd.ms-cab-compressed",
55
+ ".cc" => "text/x-c",
56
+ ".chm" => "application/vnd.ms-htmlhelp",
57
+ ".class" => "application/octet-stream",
58
+ ".com" => "application/x-msdownload",
59
+ ".conf" => "text/plain",
60
+ ".cpp" => "text/x-c",
61
+ ".crt" => "application/x-x509-ca-cert",
62
+ ".css" => "text/css",
63
+ ".csv" => "text/csv",
64
+ ".cxx" => "text/x-c",
65
+ ".deb" => "application/x-debian-package",
66
+ ".der" => "application/x-x509-ca-cert",
67
+ ".diff" => "text/x-diff",
68
+ ".djv" => "image/vnd.djvu",
69
+ ".djvu" => "image/vnd.djvu",
70
+ ".dll" => "application/x-msdownload",
71
+ ".dmg" => "application/octet-stream",
72
+ ".doc" => "application/msword",
73
+ ".dot" => "application/msword",
74
+ ".dtd" => "application/xml-dtd",
75
+ ".dvi" => "application/x-dvi",
76
+ ".ear" => "application/java-archive",
77
+ ".eml" => "message/rfc822",
78
+ ".eps" => "application/postscript",
79
+ ".exe" => "application/x-msdownload",
80
+ ".f" => "text/x-fortran",
81
+ ".f77" => "text/x-fortran",
82
+ ".f90" => "text/x-fortran",
83
+ ".flv" => "video/x-flv",
84
+ ".for" => "text/x-fortran",
85
+ ".gem" => "application/octet-stream",
86
+ ".gemspec" => "text/x-script.ruby",
87
+ ".gif" => "image/gif",
88
+ ".gz" => "application/x-gzip",
89
+ ".h" => "text/x-c",
90
+ ".hh" => "text/x-c",
91
+ ".htm" => "text/html",
92
+ ".html" => "text/html",
93
+ ".ico" => "image/vnd.microsoft.icon",
94
+ ".ics" => "text/calendar",
95
+ ".ifb" => "text/calendar",
96
+ ".iso" => "application/octet-stream",
97
+ ".jar" => "application/java-archive",
98
+ ".java" => "text/x-java-source",
99
+ ".jnlp" => "application/x-java-jnlp-file",
100
+ ".jpeg" => "image/jpeg",
101
+ ".jpg" => "image/jpeg",
102
+ ".js" => "application/javascript",
103
+ ".json" => "application/json",
104
+ ".log" => "text/plain",
105
+ ".m3u" => "audio/x-mpegurl",
106
+ ".m4v" => "video/mp4",
107
+ ".man" => "text/troff",
108
+ ".mathml" => "application/mathml+xml",
109
+ ".mbox" => "application/mbox",
110
+ ".mdoc" => "text/troff",
111
+ ".me" => "text/troff",
112
+ ".mid" => "audio/midi",
113
+ ".midi" => "audio/midi",
114
+ ".mime" => "message/rfc822",
115
+ ".mml" => "application/mathml+xml",
116
+ ".mng" => "video/x-mng",
117
+ ".mov" => "video/quicktime",
118
+ ".mp3" => "audio/mpeg",
119
+ ".mp4" => "video/mp4",
120
+ ".mp4v" => "video/mp4",
121
+ ".mpeg" => "video/mpeg",
122
+ ".mpg" => "video/mpeg",
123
+ ".ms" => "text/troff",
124
+ ".msi" => "application/x-msdownload",
125
+ ".odp" => "application/vnd.oasis.opendocument.presentation",
126
+ ".ods" => "application/vnd.oasis.opendocument.spreadsheet",
127
+ ".odt" => "application/vnd.oasis.opendocument.text",
128
+ ".ogg" => "application/ogg",
129
+ ".p" => "text/x-pascal",
130
+ ".pas" => "text/x-pascal",
131
+ ".pbm" => "image/x-portable-bitmap",
132
+ ".pdf" => "application/pdf",
133
+ ".pem" => "application/x-x509-ca-cert",
134
+ ".pgm" => "image/x-portable-graymap",
135
+ ".pgp" => "application/pgp-encrypted",
136
+ ".pkg" => "application/octet-stream",
137
+ ".pl" => "text/x-script.perl",
138
+ ".pm" => "text/x-script.perl-module",
139
+ ".png" => "image/png",
140
+ ".pnm" => "image/x-portable-anymap",
141
+ ".ppm" => "image/x-portable-pixmap",
142
+ ".pps" => "application/vnd.ms-powerpoint",
143
+ ".ppt" => "application/vnd.ms-powerpoint",
144
+ ".ps" => "application/postscript",
145
+ ".psd" => "image/vnd.adobe.photoshop",
146
+ ".py" => "text/x-script.python",
147
+ ".qt" => "video/quicktime",
148
+ ".ra" => "audio/x-pn-realaudio",
149
+ ".rake" => "text/x-script.ruby",
150
+ ".ram" => "audio/x-pn-realaudio",
151
+ ".rar" => "application/x-rar-compressed",
152
+ ".rb" => "text/x-script.ruby",
153
+ ".rdf" => "application/rdf+xml",
154
+ ".roff" => "text/troff",
155
+ ".rpm" => "application/x-redhat-package-manager",
156
+ ".rss" => "application/rss+xml",
157
+ ".rtf" => "application/rtf",
158
+ ".ru" => "text/x-script.ruby",
159
+ ".s" => "text/x-asm",
160
+ ".sgm" => "text/sgml",
161
+ ".sgml" => "text/sgml",
162
+ ".sh" => "application/x-sh",
163
+ ".sig" => "application/pgp-signature",
164
+ ".snd" => "audio/basic",
165
+ ".so" => "application/octet-stream",
166
+ ".svg" => "image/svg+xml",
167
+ ".svgz" => "image/svg+xml",
168
+ ".swf" => "application/x-shockwave-flash",
169
+ ".t" => "text/troff",
170
+ ".tar" => "application/x-tar",
171
+ ".tbz" => "application/x-bzip-compressed-tar",
172
+ ".tcl" => "application/x-tcl",
173
+ ".tex" => "application/x-tex",
174
+ ".texi" => "application/x-texinfo",
175
+ ".texinfo" => "application/x-texinfo",
176
+ ".text" => "text/plain",
177
+ ".tif" => "image/tiff",
178
+ ".tiff" => "image/tiff",
179
+ ".torrent" => "application/x-bittorrent",
180
+ ".tr" => "text/troff",
181
+ ".txt" => "text/plain",
182
+ ".vcf" => "text/x-vcard",
183
+ ".vcs" => "text/x-vcalendar",
184
+ ".vrml" => "model/vrml",
185
+ ".war" => "application/java-archive",
186
+ ".wav" => "audio/x-wav",
187
+ ".wma" => "audio/x-ms-wma",
188
+ ".wmv" => "video/x-ms-wmv",
189
+ ".wmx" => "video/x-ms-wmx",
190
+ ".wrl" => "model/vrml",
191
+ ".wsdl" => "application/wsdl+xml",
192
+ ".xbm" => "image/x-xbitmap",
193
+ ".xhtml" => "application/xhtml+xml",
194
+ ".xls" => "application/vnd.ms-excel",
195
+ ".xml" => "application/xml",
196
+ ".xpm" => "image/x-xpixmap",
197
+ ".xsl" => "application/xml",
198
+ ".xslt" => "application/xslt+xml",
199
+ ".yaml" => "text/yaml",
200
+ ".yml" => "text/yaml",
201
+ ".zip" => "application/zip",
202
+ }
203
+ end
204
+ end
data/lib/rack/mock.rb ADDED
@@ -0,0 +1,160 @@
1
+ require 'uri'
2
+ require 'stringio'
3
+ require 'rack/lint'
4
+ require 'rack/utils'
5
+ require 'rack/response'
6
+
7
+ module Rack
8
+ # Rack::MockRequest helps testing your Rack application without
9
+ # actually using HTTP.
10
+ #
11
+ # After performing a request on a URL with get/post/put/delete, it
12
+ # returns a MockResponse with useful helper methods for effective
13
+ # testing.
14
+ #
15
+ # You can pass a hash with additional configuration to the
16
+ # get/post/put/delete.
17
+ # <tt>:input</tt>:: A String or IO-like to be used as rack.input.
18
+ # <tt>:fatal</tt>:: Raise a FatalWarning if the app writes to rack.errors.
19
+ # <tt>:lint</tt>:: If true, wrap the application in a Rack::Lint.
20
+
21
+ class MockRequest
22
+ class FatalWarning < RuntimeError
23
+ end
24
+
25
+ class FatalWarner
26
+ def puts(warning)
27
+ raise FatalWarning, warning
28
+ end
29
+
30
+ def write(warning)
31
+ raise FatalWarning, warning
32
+ end
33
+
34
+ def flush
35
+ end
36
+
37
+ def string
38
+ ""
39
+ end
40
+ end
41
+
42
+ DEFAULT_ENV = {
43
+ "rack.version" => [0,1],
44
+ "rack.input" => StringIO.new,
45
+ "rack.errors" => StringIO.new,
46
+ "rack.multithread" => true,
47
+ "rack.multiprocess" => true,
48
+ "rack.run_once" => false,
49
+ }
50
+
51
+ def initialize(app)
52
+ @app = app
53
+ end
54
+
55
+ def get(uri, opts={}) request("GET", uri, opts) end
56
+ def post(uri, opts={}) request("POST", uri, opts) end
57
+ def put(uri, opts={}) request("PUT", uri, opts) end
58
+ def delete(uri, opts={}) request("DELETE", uri, opts) end
59
+
60
+ def request(method="GET", uri="", opts={})
61
+ env = self.class.env_for(uri, opts.merge(:method => method))
62
+
63
+ if opts[:lint]
64
+ app = Rack::Lint.new(@app)
65
+ else
66
+ app = @app
67
+ end
68
+
69
+ errors = env["rack.errors"]
70
+ MockResponse.new(*(app.call(env) + [errors]))
71
+ end
72
+
73
+ # Return the Rack environment used for a request to +uri+.
74
+ def self.env_for(uri="", opts={})
75
+ uri = URI(uri)
76
+ env = DEFAULT_ENV.dup
77
+
78
+ env["REQUEST_METHOD"] = opts[:method] || "GET"
79
+ env["SERVER_NAME"] = uri.host || "example.org"
80
+ env["SERVER_PORT"] = uri.port ? uri.port.to_s : "80"
81
+ env["QUERY_STRING"] = uri.query.to_s
82
+ env["PATH_INFO"] = (!uri.path || uri.path.empty?) ? "/" : uri.path
83
+ env["rack.url_scheme"] = uri.scheme || "http"
84
+
85
+ env["SCRIPT_NAME"] = opts[:script_name] || ""
86
+
87
+ if opts[:fatal]
88
+ env["rack.errors"] = FatalWarner.new
89
+ else
90
+ env["rack.errors"] = StringIO.new
91
+ end
92
+
93
+ opts[:input] ||= ""
94
+ if String === opts[:input]
95
+ env["rack.input"] = StringIO.new(opts[:input])
96
+ else
97
+ env["rack.input"] = opts[:input]
98
+ end
99
+
100
+ opts.each { |field, value|
101
+ env[field] = value if String === field
102
+ }
103
+
104
+ env
105
+ end
106
+ end
107
+
108
+ # Rack::MockResponse provides useful helpers for testing your apps.
109
+ # Usually, you don't create the MockResponse on your own, but use
110
+ # MockRequest.
111
+
112
+ class MockResponse
113
+ def initialize(status, headers, body, errors=StringIO.new(""))
114
+ @status = status.to_i
115
+
116
+ @original_headers = headers
117
+ @headers = Rack::Utils::HeaderHash.new
118
+ headers.each { |field, values|
119
+ values.each { |value|
120
+ @headers[field] = value
121
+ }
122
+ @headers[field] = "" if values.empty?
123
+ }
124
+
125
+ @body = ""
126
+ body.each { |part| @body << part }
127
+
128
+ @errors = errors.string
129
+ end
130
+
131
+ # Status
132
+ attr_reader :status
133
+
134
+ # Headers
135
+ attr_reader :headers, :original_headers
136
+
137
+ def [](field)
138
+ headers[field]
139
+ end
140
+
141
+
142
+ # Body
143
+ attr_reader :body
144
+
145
+ def =~(other)
146
+ @body =~ other
147
+ end
148
+
149
+ def match(other)
150
+ @body.match other
151
+ end
152
+
153
+
154
+ # Errors
155
+ attr_accessor :errors
156
+
157
+
158
+ include Response::Helpers
159
+ end
160
+ end