actionpack 2.2.3 → 2.3.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- data/CHANGELOG +433 -375
- data/MIT-LICENSE +1 -1
- data/README +21 -75
- data/Rakefile +1 -1
- data/lib/action_controller.rb +80 -43
- data/lib/action_controller/assertions/model_assertions.rb +1 -0
- data/lib/action_controller/assertions/response_assertions.rb +43 -16
- data/lib/action_controller/assertions/routing_assertions.rb +1 -1
- data/lib/action_controller/assertions/selector_assertions.rb +17 -12
- data/lib/action_controller/assertions/tag_assertions.rb +1 -4
- data/lib/action_controller/base.rb +153 -82
- data/lib/action_controller/benchmarking.rb +9 -9
- data/lib/action_controller/caching.rb +9 -11
- data/lib/action_controller/caching/actions.rb +11 -18
- data/lib/action_controller/caching/fragments.rb +28 -20
- data/lib/action_controller/caching/pages.rb +13 -15
- data/lib/action_controller/caching/sweeping.rb +2 -2
- data/lib/action_controller/cgi_ext.rb +0 -1
- data/lib/action_controller/cgi_ext/cookie.rb +2 -0
- data/lib/action_controller/cgi_process.rb +54 -162
- data/lib/action_controller/cookies.rb +13 -25
- data/lib/action_controller/dispatcher.rb +43 -122
- data/lib/action_controller/failsafe.rb +52 -0
- data/lib/action_controller/flash.rb +38 -47
- data/lib/action_controller/helpers.rb +13 -9
- data/lib/action_controller/http_authentication.rb +203 -23
- data/lib/action_controller/integration.rb +126 -70
- data/lib/action_controller/layout.rb +36 -39
- data/lib/action_controller/middleware_stack.rb +119 -0
- data/lib/action_controller/middlewares.rb +13 -0
- data/lib/action_controller/mime_responds.rb +19 -4
- data/lib/action_controller/mime_type.rb +8 -0
- data/lib/action_controller/params_parser.rb +71 -0
- data/lib/action_controller/performance_test.rb +0 -1
- data/lib/action_controller/polymorphic_routes.rb +36 -30
- data/lib/action_controller/reloader.rb +14 -0
- data/lib/action_controller/request.rb +107 -499
- data/lib/action_controller/request_forgery_protection.rb +7 -39
- data/lib/action_controller/rescue.rb +55 -35
- data/lib/action_controller/resources.rb +34 -31
- data/lib/action_controller/response.rb +99 -57
- data/lib/action_controller/rewindable_input.rb +28 -0
- data/lib/action_controller/routing.rb +7 -7
- data/lib/action_controller/routing/builder.rb +4 -1
- data/lib/action_controller/routing/optimisations.rb +1 -1
- data/lib/action_controller/routing/recognition_optimisation.rb +1 -2
- data/lib/action_controller/routing/route.rb +15 -5
- data/lib/action_controller/routing/route_set.rb +82 -35
- data/lib/action_controller/routing/segments.rb +35 -0
- data/lib/action_controller/session/abstract_store.rb +181 -0
- data/lib/action_controller/session/cookie_store.rb +197 -175
- data/lib/action_controller/session/mem_cache_store.rb +36 -83
- data/lib/action_controller/session_management.rb +26 -134
- data/lib/action_controller/streaming.rb +24 -7
- data/lib/action_controller/templates/rescues/diagnostics.erb +2 -2
- data/lib/action_controller/templates/rescues/template_error.erb +2 -2
- data/lib/action_controller/test_case.rb +87 -30
- data/lib/action_controller/test_process.rb +145 -104
- data/lib/action_controller/uploaded_file.rb +44 -0
- data/lib/action_controller/url_rewriter.rb +3 -6
- data/lib/action_controller/vendor/html-scanner.rb +16 -0
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +1 -1
- data/lib/action_controller/vendor/rack-1.0/rack.rb +89 -0
- data/lib/action_controller/vendor/rack-1.0/rack/adapter/camping.rb +22 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/handler.rb +37 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/request.rb +37 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/basic.rb +58 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/md5.rb +124 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/nonce.rb +51 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/params.rb +55 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/request.rb +40 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/openid.rb +480 -0
- data/lib/action_controller/vendor/rack-1.0/rack/builder.rb +63 -0
- data/lib/action_controller/vendor/rack-1.0/rack/cascade.rb +36 -0
- data/lib/action_controller/vendor/rack-1.0/rack/chunked.rb +49 -0
- data/lib/action_controller/vendor/rack-1.0/rack/commonlogger.rb +61 -0
- data/lib/action_controller/vendor/rack-1.0/rack/conditionalget.rb +45 -0
- data/lib/action_controller/vendor/rack-1.0/rack/content_length.rb +29 -0
- data/lib/action_controller/vendor/rack-1.0/rack/content_type.rb +23 -0
- data/lib/action_controller/vendor/rack-1.0/rack/deflater.rb +85 -0
- data/lib/action_controller/vendor/rack-1.0/rack/directory.rb +153 -0
- data/lib/action_controller/vendor/rack-1.0/rack/file.rb +88 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler.rb +48 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/cgi.rb +61 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/evented_mongrel.rb +8 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/fastcgi.rb +89 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/lsws.rb +55 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb +84 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/scgi.rb +59 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/swiftiplied_mongrel.rb +8 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/thin.rb +18 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/webrick.rb +67 -0
- data/lib/action_controller/vendor/rack-1.0/rack/head.rb +19 -0
- data/lib/action_controller/vendor/rack-1.0/rack/lint.rb +462 -0
- data/lib/action_controller/vendor/rack-1.0/rack/lobster.rb +65 -0
- data/lib/action_controller/vendor/rack-1.0/rack/lock.rb +16 -0
- data/lib/action_controller/vendor/rack-1.0/rack/methodoverride.rb +27 -0
- data/lib/action_controller/vendor/rack-1.0/rack/mime.rb +204 -0
- data/lib/action_controller/vendor/rack-1.0/rack/mock.rb +160 -0
- data/lib/action_controller/vendor/rack-1.0/rack/recursive.rb +57 -0
- data/lib/action_controller/vendor/rack-1.0/rack/reloader.rb +64 -0
- data/lib/action_controller/vendor/rack-1.0/rack/request.rb +241 -0
- data/lib/action_controller/vendor/rack-1.0/rack/response.rb +179 -0
- data/lib/action_controller/vendor/rack-1.0/rack/session/abstract/id.rb +142 -0
- data/lib/action_controller/vendor/rack-1.0/rack/session/cookie.rb +91 -0
- data/lib/action_controller/vendor/rack-1.0/rack/session/memcache.rb +109 -0
- data/lib/action_controller/vendor/rack-1.0/rack/session/pool.rb +100 -0
- data/lib/action_controller/vendor/rack-1.0/rack/showexceptions.rb +349 -0
- data/lib/action_controller/vendor/rack-1.0/rack/showstatus.rb +106 -0
- data/lib/action_controller/vendor/rack-1.0/rack/static.rb +38 -0
- data/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb +55 -0
- data/lib/action_controller/vendor/rack-1.0/rack/utils.rb +392 -0
- data/lib/action_controller/verification.rb +1 -1
- data/lib/action_pack.rb +1 -1
- data/lib/action_pack/version.rb +2 -2
- data/lib/action_view.rb +22 -17
- data/lib/action_view/base.rb +53 -79
- data/lib/action_view/erb/util.rb +38 -0
- data/lib/action_view/helpers.rb +24 -5
- data/lib/action_view/helpers/active_record_helper.rb +2 -2
- data/lib/action_view/helpers/asset_tag_helper.rb +81 -50
- data/lib/action_view/helpers/atom_feed_helper.rb +1 -1
- data/lib/action_view/helpers/benchmark_helper.rb +26 -5
- data/lib/action_view/helpers/date_helper.rb +82 -7
- data/lib/action_view/helpers/form_helper.rb +295 -64
- data/lib/action_view/helpers/form_options_helper.rb +160 -18
- data/lib/action_view/helpers/form_tag_helper.rb +2 -2
- data/lib/action_view/helpers/number_helper.rb +31 -18
- data/lib/action_view/helpers/prototype_helper.rb +2 -12
- data/lib/action_view/helpers/sanitize_helper.rb +0 -10
- data/lib/action_view/helpers/scriptaculous_helper.rb +1 -0
- data/lib/action_view/helpers/tag_helper.rb +3 -4
- data/lib/action_view/helpers/text_helper.rb +99 -122
- data/lib/action_view/helpers/translation_helper.rb +19 -1
- data/lib/action_view/helpers/url_helper.rb +25 -2
- data/lib/action_view/inline_template.rb +1 -1
- data/lib/action_view/locale/en.yml +19 -1
- data/lib/action_view/partials.rb +46 -9
- data/lib/action_view/paths.rb +28 -84
- data/lib/action_view/reloadable_template.rb +117 -0
- data/lib/action_view/renderable.rb +28 -35
- data/lib/action_view/renderable_partial.rb +3 -4
- data/lib/action_view/template.rb +172 -31
- data/lib/action_view/template_error.rb +8 -9
- data/lib/action_view/template_handler.rb +1 -1
- data/lib/action_view/template_handlers.rb +9 -6
- data/lib/action_view/template_handlers/erb.rb +2 -39
- data/lib/action_view/template_handlers/rjs.rb +1 -0
- data/lib/action_view/test_case.rb +27 -1
- data/test/abstract_unit.rb +23 -17
- data/test/active_record_unit.rb +5 -4
- data/test/activerecord/active_record_store_test.rb +139 -106
- data/test/activerecord/render_partial_with_record_identification_test.rb +5 -21
- data/test/controller/action_pack_assertions_test.rb +25 -23
- data/test/controller/addresses_render_test.rb +3 -6
- data/test/controller/assert_select_test.rb +83 -70
- data/test/controller/base_test.rb +11 -13
- data/test/controller/benchmark_test.rb +3 -3
- data/test/controller/caching_test.rb +34 -24
- data/test/controller/capture_test.rb +3 -6
- data/test/controller/content_type_test.rb +3 -6
- data/test/controller/cookie_test.rb +31 -66
- data/test/controller/deprecation/deprecated_base_methods_test.rb +9 -11
- data/test/controller/dispatcher_test.rb +23 -28
- data/test/controller/fake_models.rb +8 -0
- data/test/controller/filters_test.rb +6 -2
- data/test/controller/flash_test.rb +2 -6
- data/test/controller/helper_test.rb +15 -1
- data/test/controller/html-scanner/document_test.rb +1 -1
- data/test/controller/html-scanner/sanitizer_test.rb +1 -1
- data/test/controller/http_basic_authentication_test.rb +88 -0
- data/test/controller/http_digest_authentication_test.rb +178 -0
- data/test/controller/integration_test.rb +56 -52
- data/test/controller/layout_test.rb +46 -44
- data/test/controller/middleware_stack_test.rb +90 -0
- data/test/controller/mime_responds_test.rb +7 -11
- data/test/controller/mime_type_test.rb +9 -0
- data/test/controller/polymorphic_routes_test.rb +235 -151
- data/test/controller/rack_test.rb +52 -81
- data/test/controller/redirect_test.rb +6 -14
- data/test/controller/render_test.rb +273 -60
- data/test/controller/request/json_params_parsing_test.rb +45 -0
- data/test/controller/request/multipart_params_parsing_test.rb +223 -0
- data/test/controller/request/query_string_parsing_test.rb +120 -0
- data/test/controller/request/url_encoded_params_parsing_test.rb +184 -0
- data/test/controller/request/xml_params_parsing_test.rb +88 -0
- data/test/controller/request_forgery_protection_test.rb +17 -98
- data/test/controller/request_test.rb +45 -530
- data/test/controller/rescue_test.rb +45 -22
- data/test/controller/resources_test.rb +112 -37
- data/test/controller/routing_test.rb +1442 -1384
- data/test/controller/selector_test.rb +3 -3
- data/test/controller/send_file_test.rb +30 -3
- data/test/controller/session/cookie_store_test.rb +169 -240
- data/test/controller/session/mem_cache_store_test.rb +94 -148
- data/test/controller/session/test_session_test.rb +58 -0
- data/test/controller/test_test.rb +32 -13
- data/test/controller/url_rewriter_test.rb +54 -4
- data/test/controller/verification_test.rb +1 -1
- data/test/controller/view_paths_test.rb +15 -15
- data/test/controller/webservice_test.rb +178 -147
- data/test/fixtures/alternate_helpers/foo_helper.rb +3 -0
- data/test/fixtures/layout_tests/alt/layouts/alt.rhtml +0 -0
- data/test/fixtures/layouts/default_html.html.erb +1 -0
- data/test/fixtures/layouts/xhr.html.erb +2 -0
- data/test/fixtures/multipart/empty +10 -0
- data/test/fixtures/multipart/hello.txt +1 -0
- data/test/fixtures/multipart/none +9 -0
- data/test/fixtures/public/500.da.html +1 -0
- data/test/fixtures/quiz/questions/_question.html.erb +1 -0
- data/test/fixtures/replies.yml +1 -1
- data/test/fixtures/test/_one.html.erb +1 -0
- data/test/fixtures/test/_two.html.erb +1 -0
- data/test/fixtures/test/dont_pick_me +1 -0
- data/test/fixtures/test/hello.builder +1 -1
- data/test/fixtures/test/hello_world.da.html.erb +1 -0
- data/test/fixtures/test/hello_world.erb~ +1 -0
- data/test/fixtures/test/hello_world.pt-BR.html.erb +1 -0
- data/test/fixtures/test/malformed/malformed.en.html.erb~ +1 -0
- data/test/fixtures/test/malformed/malformed.erb~ +1 -0
- data/test/fixtures/test/malformed/malformed.html.erb~ +1 -0
- data/test/fixtures/test/render_explicit_html_template.js.rjs +1 -0
- data/test/fixtures/test/render_implicit_html_template.js.rjs +1 -0
- data/test/fixtures/test/render_implicit_html_template_from_xhr_request.da.html.erb +1 -0
- data/test/fixtures/test/render_implicit_html_template_from_xhr_request.html.erb +1 -0
- data/test/fixtures/test/render_implicit_js_template_without_layout.js.erb +1 -0
- data/test/fixtures/test/utf8.html.erb +2 -0
- data/test/template/active_record_helper_i18n_test.rb +31 -33
- data/test/template/active_record_helper_test.rb +34 -0
- data/test/template/asset_tag_helper_test.rb +52 -14
- data/test/template/atom_feed_helper_test.rb +3 -5
- data/test/template/benchmark_helper_test.rb +50 -24
- data/test/template/compiled_templates_test.rb +177 -33
- data/test/template/date_helper_i18n_test.rb +88 -81
- data/test/template/date_helper_test.rb +427 -43
- data/test/template/form_helper_test.rb +243 -44
- data/test/template/form_options_helper_test.rb +631 -565
- data/test/template/form_tag_helper_test.rb +9 -2
- data/test/template/javascript_helper_test.rb +0 -5
- data/test/template/number_helper_i18n_test.rb +60 -48
- data/test/template/number_helper_test.rb +1 -0
- data/test/template/render_test.rb +117 -35
- data/test/template/test_test.rb +4 -6
- data/test/template/text_helper_test.rb +129 -50
- data/test/template/translation_helper_test.rb +23 -19
- data/test/template/url_helper_test.rb +35 -2
- data/test/view/test_case_test.rb +8 -0
- metadata +197 -23
- data/lib/action_controller/assertions.rb +0 -69
- data/lib/action_controller/caching/sql_cache.rb +0 -18
- data/lib/action_controller/cgi_ext/session.rb +0 -53
- data/lib/action_controller/components.rb +0 -169
- data/lib/action_controller/rack_process.rb +0 -297
- data/lib/action_controller/request_profiler.rb +0 -169
- data/lib/action_controller/session/active_record_store.rb +0 -340
- data/lib/action_controller/session/drb_server.rb +0 -32
- data/lib/action_controller/session/drb_store.rb +0 -35
- data/test/controller/cgi_test.rb +0 -269
- data/test/controller/components_test.rb +0 -156
- data/test/controller/http_authentication_test.rb +0 -54
- data/test/controller/integration_upload_test.rb +0 -43
- data/test/controller/session_fixation_test.rb +0 -89
- data/test/controller/session_management_test.rb +0 -178
- data/test/fixtures/test/hello_world.js +0 -1
@@ -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,16 @@
|
|
1
|
+
module Rack
|
2
|
+
class Lock
|
3
|
+
FLAG = 'rack.multithread'.freeze
|
4
|
+
|
5
|
+
def initialize(app, lock = Mutex.new)
|
6
|
+
@app, @lock = app, lock
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
old, env[FLAG] = env[FLAG], false
|
11
|
+
@lock.synchronize { @app.call(env) }
|
12
|
+
ensure
|
13
|
+
env[FLAG] = old
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Rack
|
2
|
+
class MethodOverride
|
3
|
+
HTTP_METHODS = %w(GET HEAD PUT POST DELETE OPTIONS)
|
4
|
+
|
5
|
+
METHOD_OVERRIDE_PARAM_KEY = "_method".freeze
|
6
|
+
HTTP_METHOD_OVERRIDE_HEADER = "HTTP_X_HTTP_METHOD_OVERRIDE".freeze
|
7
|
+
|
8
|
+
def initialize(app)
|
9
|
+
@app = app
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
if env["REQUEST_METHOD"] == "POST"
|
14
|
+
req = Request.new(env)
|
15
|
+
method = req.POST[METHOD_OVERRIDE_PARAM_KEY] ||
|
16
|
+
env[HTTP_METHOD_OVERRIDE_HEADER]
|
17
|
+
method = method.to_s.upcase
|
18
|
+
if HTTP_METHODS.include?(method)
|
19
|
+
env["rack.methodoverride.original_method"] = env["REQUEST_METHOD"]
|
20
|
+
env["REQUEST_METHOD"] = method
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
@app.call(env)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -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::Mime.mime_type('.foo')
|
12
|
+
#
|
13
|
+
# This is a shortcut for:
|
14
|
+
# Rack::Mime::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::Mime::MIME_TYPES.merge!(list)
|
30
|
+
#
|
31
|
+
# To add the list mongrel provides, use:
|
32
|
+
#
|
33
|
+
# require 'mongrel/handlers'
|
34
|
+
# Rack::Mime::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
|
@@ -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
|
+
env["CONTENT_LENGTH"] ||= env["rack.input"].length.to_s
|
101
|
+
|
102
|
+
opts.each { |field, value|
|
103
|
+
env[field] = value if String === field
|
104
|
+
}
|
105
|
+
|
106
|
+
env
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# Rack::MockResponse provides useful helpers for testing your apps.
|
111
|
+
# Usually, you don't create the MockResponse on your own, but use
|
112
|
+
# MockRequest.
|
113
|
+
|
114
|
+
class MockResponse
|
115
|
+
def initialize(status, headers, body, errors=StringIO.new(""))
|
116
|
+
@status = status.to_i
|
117
|
+
|
118
|
+
@original_headers = headers
|
119
|
+
@headers = Rack::Utils::HeaderHash.new
|
120
|
+
headers.each { |field, values|
|
121
|
+
@headers[field] = values
|
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
|