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,88 @@
|
|
1
|
+
require 'time'
|
2
|
+
require 'rack/utils'
|
3
|
+
require 'rack/mime'
|
4
|
+
|
5
|
+
module Rack
|
6
|
+
# Rack::File serves files below the +root+ given, according to the
|
7
|
+
# path info of the Rack request.
|
8
|
+
#
|
9
|
+
# Handlers can detect if bodies are a Rack::File, and use mechanisms
|
10
|
+
# like sendfile on the +path+.
|
11
|
+
|
12
|
+
class File
|
13
|
+
attr_accessor :root
|
14
|
+
attr_accessor :path
|
15
|
+
|
16
|
+
alias :to_path :path
|
17
|
+
|
18
|
+
def initialize(root)
|
19
|
+
@root = root
|
20
|
+
end
|
21
|
+
|
22
|
+
def call(env)
|
23
|
+
dup._call(env)
|
24
|
+
end
|
25
|
+
|
26
|
+
F = ::File
|
27
|
+
|
28
|
+
def _call(env)
|
29
|
+
@path_info = Utils.unescape(env["PATH_INFO"])
|
30
|
+
return forbidden if @path_info.include? ".."
|
31
|
+
|
32
|
+
@path = F.join(@root, @path_info)
|
33
|
+
|
34
|
+
begin
|
35
|
+
if F.file?(@path) && F.readable?(@path)
|
36
|
+
serving
|
37
|
+
else
|
38
|
+
raise Errno::EPERM
|
39
|
+
end
|
40
|
+
rescue SystemCallError
|
41
|
+
not_found
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def forbidden
|
46
|
+
body = "Forbidden\n"
|
47
|
+
[403, {"Content-Type" => "text/plain",
|
48
|
+
"Content-Length" => body.size.to_s},
|
49
|
+
[body]]
|
50
|
+
end
|
51
|
+
|
52
|
+
# NOTE:
|
53
|
+
# We check via File::size? whether this file provides size info
|
54
|
+
# via stat (e.g. /proc files often don't), otherwise we have to
|
55
|
+
# figure it out by reading the whole file into memory. And while
|
56
|
+
# we're at it we also use this as body then.
|
57
|
+
|
58
|
+
def serving
|
59
|
+
if size = F.size?(@path)
|
60
|
+
body = self
|
61
|
+
else
|
62
|
+
body = [F.read(@path)]
|
63
|
+
size = Utils.bytesize(body.first)
|
64
|
+
end
|
65
|
+
|
66
|
+
[200, {
|
67
|
+
"Last-Modified" => F.mtime(@path).httpdate,
|
68
|
+
"Content-Type" => Mime.mime_type(F.extname(@path), 'text/plain'),
|
69
|
+
"Content-Length" => size.to_s
|
70
|
+
}, body]
|
71
|
+
end
|
72
|
+
|
73
|
+
def not_found
|
74
|
+
body = "File not found: #{@path_info}\n"
|
75
|
+
[404, {"Content-Type" => "text/plain",
|
76
|
+
"Content-Length" => body.size.to_s},
|
77
|
+
[body]]
|
78
|
+
end
|
79
|
+
|
80
|
+
def each
|
81
|
+
F.open(@path, "rb") { |file|
|
82
|
+
while part = file.read(8192)
|
83
|
+
yield part
|
84
|
+
end
|
85
|
+
}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Rack
|
2
|
+
# *Handlers* connect web servers with Rack.
|
3
|
+
#
|
4
|
+
# Rack includes Handlers for Mongrel, WEBrick, FastCGI, CGI, SCGI
|
5
|
+
# and LiteSpeed.
|
6
|
+
#
|
7
|
+
# Handlers usually are activated by calling <tt>MyHandler.run(myapp)</tt>.
|
8
|
+
# A second optional hash can be passed to include server-specific
|
9
|
+
# configuration.
|
10
|
+
module Handler
|
11
|
+
def self.get(server)
|
12
|
+
return unless server
|
13
|
+
|
14
|
+
if klass = @handlers[server]
|
15
|
+
obj = Object
|
16
|
+
klass.split("::").each { |x| obj = obj.const_get(x) }
|
17
|
+
obj
|
18
|
+
else
|
19
|
+
Rack::Handler.const_get(server.capitalize)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.register(server, klass)
|
24
|
+
@handlers ||= {}
|
25
|
+
@handlers[server] = klass
|
26
|
+
end
|
27
|
+
|
28
|
+
autoload :CGI, "rack/handler/cgi"
|
29
|
+
autoload :FastCGI, "rack/handler/fastcgi"
|
30
|
+
autoload :Mongrel, "rack/handler/mongrel"
|
31
|
+
autoload :EventedMongrel, "rack/handler/evented_mongrel"
|
32
|
+
autoload :SwiftipliedMongrel, "rack/handler/swiftiplied_mongrel"
|
33
|
+
autoload :WEBrick, "rack/handler/webrick"
|
34
|
+
autoload :LSWS, "rack/handler/lsws"
|
35
|
+
autoload :SCGI, "rack/handler/scgi"
|
36
|
+
autoload :Thin, "rack/handler/thin"
|
37
|
+
|
38
|
+
register 'cgi', 'Rack::Handler::CGI'
|
39
|
+
register 'fastcgi', 'Rack::Handler::FastCGI'
|
40
|
+
register 'mongrel', 'Rack::Handler::Mongrel'
|
41
|
+
register 'emongrel', 'Rack::Handler::EventedMongrel'
|
42
|
+
register 'smongrel', 'Rack::Handler::SwiftipliedMongrel'
|
43
|
+
register 'webrick', 'Rack::Handler::WEBrick'
|
44
|
+
register 'lsws', 'Rack::Handler::LSWS'
|
45
|
+
register 'scgi', 'Rack::Handler::SCGI'
|
46
|
+
register 'thin', 'Rack::Handler::Thin'
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'rack/content_length'
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
module Handler
|
5
|
+
class CGI
|
6
|
+
def self.run(app, options=nil)
|
7
|
+
serve app
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.serve(app)
|
11
|
+
app = ContentLength.new(app)
|
12
|
+
|
13
|
+
env = ENV.to_hash
|
14
|
+
env.delete "HTTP_CONTENT_LENGTH"
|
15
|
+
|
16
|
+
env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
|
17
|
+
|
18
|
+
env.update({"rack.version" => [0,1],
|
19
|
+
"rack.input" => $stdin,
|
20
|
+
"rack.errors" => $stderr,
|
21
|
+
|
22
|
+
"rack.multithread" => false,
|
23
|
+
"rack.multiprocess" => true,
|
24
|
+
"rack.run_once" => true,
|
25
|
+
|
26
|
+
"rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
|
27
|
+
})
|
28
|
+
|
29
|
+
env["QUERY_STRING"] ||= ""
|
30
|
+
env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
|
31
|
+
env["REQUEST_PATH"] ||= "/"
|
32
|
+
|
33
|
+
status, headers, body = app.call(env)
|
34
|
+
begin
|
35
|
+
send_headers status, headers
|
36
|
+
send_body body
|
37
|
+
ensure
|
38
|
+
body.close if body.respond_to? :close
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.send_headers(status, headers)
|
43
|
+
STDOUT.print "Status: #{status}\r\n"
|
44
|
+
headers.each { |k, vs|
|
45
|
+
vs.split("\n").each { |v|
|
46
|
+
STDOUT.print "#{k}: #{v}\r\n"
|
47
|
+
}
|
48
|
+
}
|
49
|
+
STDOUT.print "\r\n"
|
50
|
+
STDOUT.flush
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.send_body(body)
|
54
|
+
body.each { |part|
|
55
|
+
STDOUT.print part
|
56
|
+
STDOUT.flush
|
57
|
+
}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'fcgi'
|
2
|
+
require 'socket'
|
3
|
+
require 'rack/content_length'
|
4
|
+
|
5
|
+
module Rack
|
6
|
+
module Handler
|
7
|
+
class FastCGI
|
8
|
+
def self.run(app, options={})
|
9
|
+
file = options[:File] and STDIN.reopen(UNIXServer.new(file))
|
10
|
+
port = options[:Port] and STDIN.reopen(TCPServer.new(port))
|
11
|
+
FCGI.each { |request|
|
12
|
+
serve request, app
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
module ProperStream # :nodoc:
|
17
|
+
def each # This is missing by default.
|
18
|
+
while line = gets
|
19
|
+
yield line
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def read(*args)
|
24
|
+
if args.empty?
|
25
|
+
super || "" # Empty string on EOF.
|
26
|
+
else
|
27
|
+
super
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.serve(request, app)
|
33
|
+
app = Rack::ContentLength.new(app)
|
34
|
+
|
35
|
+
env = request.env
|
36
|
+
env.delete "HTTP_CONTENT_LENGTH"
|
37
|
+
|
38
|
+
request.in.extend ProperStream
|
39
|
+
|
40
|
+
env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
|
41
|
+
|
42
|
+
env.update({"rack.version" => [0,1],
|
43
|
+
"rack.input" => request.in,
|
44
|
+
"rack.errors" => request.err,
|
45
|
+
|
46
|
+
"rack.multithread" => false,
|
47
|
+
"rack.multiprocess" => true,
|
48
|
+
"rack.run_once" => false,
|
49
|
+
|
50
|
+
"rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http"
|
51
|
+
})
|
52
|
+
|
53
|
+
env["QUERY_STRING"] ||= ""
|
54
|
+
env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
|
55
|
+
env["REQUEST_PATH"] ||= "/"
|
56
|
+
env.delete "PATH_INFO" if env["PATH_INFO"] == ""
|
57
|
+
env.delete "CONTENT_TYPE" if env["CONTENT_TYPE"] == ""
|
58
|
+
env.delete "CONTENT_LENGTH" if env["CONTENT_LENGTH"] == ""
|
59
|
+
|
60
|
+
status, headers, body = app.call(env)
|
61
|
+
begin
|
62
|
+
send_headers request.out, status, headers
|
63
|
+
send_body request.out, body
|
64
|
+
ensure
|
65
|
+
body.close if body.respond_to? :close
|
66
|
+
request.finish
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.send_headers(out, status, headers)
|
71
|
+
out.print "Status: #{status}\r\n"
|
72
|
+
headers.each { |k, vs|
|
73
|
+
vs.split("\n").each { |v|
|
74
|
+
out.print "#{k}: #{v}\r\n"
|
75
|
+
}
|
76
|
+
}
|
77
|
+
out.print "\r\n"
|
78
|
+
out.flush
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.send_body(out, body)
|
82
|
+
body.each { |part|
|
83
|
+
out.print part
|
84
|
+
out.flush
|
85
|
+
}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'lsapi'
|
2
|
+
require 'rack/content_length'
|
3
|
+
|
4
|
+
module Rack
|
5
|
+
module Handler
|
6
|
+
class LSWS
|
7
|
+
def self.run(app, options=nil)
|
8
|
+
while LSAPI.accept != nil
|
9
|
+
serve app
|
10
|
+
end
|
11
|
+
end
|
12
|
+
def self.serve(app)
|
13
|
+
app = Rack::ContentLength.new(app)
|
14
|
+
|
15
|
+
env = ENV.to_hash
|
16
|
+
env.delete "HTTP_CONTENT_LENGTH"
|
17
|
+
env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
|
18
|
+
env.update({"rack.version" => [0,1],
|
19
|
+
"rack.input" => StringIO.new($stdin.read.to_s),
|
20
|
+
"rack.errors" => $stderr,
|
21
|
+
"rack.multithread" => false,
|
22
|
+
"rack.multiprocess" => true,
|
23
|
+
"rack.run_once" => false,
|
24
|
+
"rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
|
25
|
+
})
|
26
|
+
env["QUERY_STRING"] ||= ""
|
27
|
+
env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
|
28
|
+
env["REQUEST_PATH"] ||= "/"
|
29
|
+
status, headers, body = app.call(env)
|
30
|
+
begin
|
31
|
+
send_headers status, headers
|
32
|
+
send_body body
|
33
|
+
ensure
|
34
|
+
body.close if body.respond_to? :close
|
35
|
+
end
|
36
|
+
end
|
37
|
+
def self.send_headers(status, headers)
|
38
|
+
print "Status: #{status}\r\n"
|
39
|
+
headers.each { |k, vs|
|
40
|
+
vs.split("\n").each { |v|
|
41
|
+
print "#{k}: #{v}\r\n"
|
42
|
+
}
|
43
|
+
}
|
44
|
+
print "\r\n"
|
45
|
+
STDOUT.flush
|
46
|
+
end
|
47
|
+
def self.send_body(body)
|
48
|
+
body.each { |part|
|
49
|
+
print part
|
50
|
+
STDOUT.flush
|
51
|
+
}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'mongrel'
|
2
|
+
require 'stringio'
|
3
|
+
require 'rack/content_length'
|
4
|
+
require 'rack/chunked'
|
5
|
+
|
6
|
+
module Rack
|
7
|
+
module Handler
|
8
|
+
class Mongrel < ::Mongrel::HttpHandler
|
9
|
+
def self.run(app, options={})
|
10
|
+
server = ::Mongrel::HttpServer.new(options[:Host] || '0.0.0.0',
|
11
|
+
options[:Port] || 8080)
|
12
|
+
# Acts like Rack::URLMap, utilizing Mongrel's own path finding methods.
|
13
|
+
# Use is similar to #run, replacing the app argument with a hash of
|
14
|
+
# { path=>app, ... } or an instance of Rack::URLMap.
|
15
|
+
if options[:map]
|
16
|
+
if app.is_a? Hash
|
17
|
+
app.each do |path, appl|
|
18
|
+
path = '/'+path unless path[0] == ?/
|
19
|
+
server.register(path, Rack::Handler::Mongrel.new(appl))
|
20
|
+
end
|
21
|
+
elsif app.is_a? URLMap
|
22
|
+
app.instance_variable_get(:@mapping).each do |(host, path, appl)|
|
23
|
+
next if !host.nil? && !options[:Host].nil? && options[:Host] != host
|
24
|
+
path = '/'+path unless path[0] == ?/
|
25
|
+
server.register(path, Rack::Handler::Mongrel.new(appl))
|
26
|
+
end
|
27
|
+
else
|
28
|
+
raise ArgumentError, "first argument should be a Hash or URLMap"
|
29
|
+
end
|
30
|
+
else
|
31
|
+
server.register('/', Rack::Handler::Mongrel.new(app))
|
32
|
+
end
|
33
|
+
yield server if block_given?
|
34
|
+
server.run.join
|
35
|
+
end
|
36
|
+
|
37
|
+
def initialize(app)
|
38
|
+
@app = Rack::Chunked.new(Rack::ContentLength.new(app))
|
39
|
+
end
|
40
|
+
|
41
|
+
def process(request, response)
|
42
|
+
env = {}.replace(request.params)
|
43
|
+
env.delete "HTTP_CONTENT_TYPE"
|
44
|
+
env.delete "HTTP_CONTENT_LENGTH"
|
45
|
+
|
46
|
+
env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
|
47
|
+
|
48
|
+
env.update({"rack.version" => [0,1],
|
49
|
+
"rack.input" => request.body || StringIO.new(""),
|
50
|
+
"rack.errors" => $stderr,
|
51
|
+
|
52
|
+
"rack.multithread" => true,
|
53
|
+
"rack.multiprocess" => false, # ???
|
54
|
+
"rack.run_once" => false,
|
55
|
+
|
56
|
+
"rack.url_scheme" => "http",
|
57
|
+
})
|
58
|
+
env["QUERY_STRING"] ||= ""
|
59
|
+
env.delete "PATH_INFO" if env["PATH_INFO"] == ""
|
60
|
+
|
61
|
+
status, headers, body = @app.call(env)
|
62
|
+
|
63
|
+
begin
|
64
|
+
response.status = status.to_i
|
65
|
+
response.send_status(nil)
|
66
|
+
|
67
|
+
headers.each { |k, vs|
|
68
|
+
vs.split("\n").each { |v|
|
69
|
+
response.header[k] = v
|
70
|
+
}
|
71
|
+
}
|
72
|
+
response.send_header
|
73
|
+
|
74
|
+
body.each { |part|
|
75
|
+
response.write part
|
76
|
+
response.socket.flush
|
77
|
+
}
|
78
|
+
ensure
|
79
|
+
body.close if body.respond_to? :close
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'scgi'
|
2
|
+
require 'stringio'
|
3
|
+
require 'rack/content_length'
|
4
|
+
require 'rack/chunked'
|
5
|
+
|
6
|
+
module Rack
|
7
|
+
module Handler
|
8
|
+
class SCGI < ::SCGI::Processor
|
9
|
+
attr_accessor :app
|
10
|
+
|
11
|
+
def self.run(app, options=nil)
|
12
|
+
new(options.merge(:app=>app,
|
13
|
+
:host=>options[:Host],
|
14
|
+
:port=>options[:Port],
|
15
|
+
:socket=>options[:Socket])).listen
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(settings = {})
|
19
|
+
@app = Rack::Chunked.new(Rack::ContentLength.new(settings[:app]))
|
20
|
+
@log = Object.new
|
21
|
+
def @log.info(*args); end
|
22
|
+
def @log.error(*args); end
|
23
|
+
super(settings)
|
24
|
+
end
|
25
|
+
|
26
|
+
def process_request(request, input_body, socket)
|
27
|
+
env = {}.replace(request)
|
28
|
+
env.delete "HTTP_CONTENT_TYPE"
|
29
|
+
env.delete "HTTP_CONTENT_LENGTH"
|
30
|
+
env["REQUEST_PATH"], env["QUERY_STRING"] = env["REQUEST_URI"].split('?', 2)
|
31
|
+
env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
|
32
|
+
env["PATH_INFO"] = env["REQUEST_PATH"]
|
33
|
+
env["QUERY_STRING"] ||= ""
|
34
|
+
env["SCRIPT_NAME"] = ""
|
35
|
+
env.update({"rack.version" => [0,1],
|
36
|
+
"rack.input" => StringIO.new(input_body),
|
37
|
+
"rack.errors" => $stderr,
|
38
|
+
|
39
|
+
"rack.multithread" => true,
|
40
|
+
"rack.multiprocess" => true,
|
41
|
+
"rack.run_once" => false,
|
42
|
+
|
43
|
+
"rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http"
|
44
|
+
})
|
45
|
+
status, headers, body = app.call(env)
|
46
|
+
begin
|
47
|
+
socket.write("Status: #{status}\r\n")
|
48
|
+
headers.each do |k, vs|
|
49
|
+
vs.split("\n").each { |v| socket.write("#{k}: #{v}\r\n")}
|
50
|
+
end
|
51
|
+
socket.write("\r\n")
|
52
|
+
body.each {|s| socket.write(s)}
|
53
|
+
ensure
|
54
|
+
body.close if body.respond_to? :close
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|