diy_rails 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -2
- data/lib/diy_rails/array.rb +5 -0
- data/lib/diy_rails/routing.rb +10 -0
- data/lib/diy_rails/version.rb +1 -1
- data/lib/diy_rails.rb +25 -3
- metadata +28 -151
- data/vendor/bundle/ruby/3.0.0/bin/rackup +0 -29
- data/vendor/bundle/ruby/3.0.0/bin/rake +0 -29
- data/vendor/bundle/ruby/3.0.0/cache/rack-2.2.4.gem +0 -0
- data/vendor/bundle/ruby/3.0.0/cache/rake-13.0.6.gem +0 -0
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/CHANGELOG.md +0 -708
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/CONTRIBUTING.md +0 -136
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/MIT-LICENSE +0 -20
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/README.rdoc +0 -306
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/Rakefile +0 -130
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/SPEC.rdoc +0 -288
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/bin/rackup +0 -5
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/contrib/rack.png +0 -0
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/contrib/rack.svg +0 -150
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/contrib/rack_logo.svg +0 -164
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/contrib/rdoc.css +0 -412
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/example/lobster.ru +0 -6
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/example/protectedlobster.rb +0 -16
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/example/protectedlobster.ru +0 -10
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/auth/abstract/handler.rb +0 -39
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/auth/abstract/request.rb +0 -47
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/auth/basic.rb +0 -61
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/auth/digest/md5.rb +0 -131
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/auth/digest/nonce.rb +0 -54
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/auth/digest/params.rb +0 -54
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/auth/digest/request.rb +0 -43
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/body_proxy.rb +0 -45
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/builder.rb +0 -257
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/cascade.rb +0 -68
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/chunked.rb +0 -117
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/common_logger.rb +0 -83
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/conditional_get.rb +0 -83
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/config.rb +0 -22
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/content_length.rb +0 -38
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/content_type.rb +0 -30
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/core_ext/regexp.rb +0 -14
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/deflater.rb +0 -144
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/directory.rb +0 -199
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/etag.rb +0 -77
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/events.rb +0 -153
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/file.rb +0 -7
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/files.rb +0 -218
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/handler/cgi.rb +0 -59
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/handler/fastcgi.rb +0 -100
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/handler/lsws.rb +0 -61
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/handler/scgi.rb +0 -71
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/handler/thin.rb +0 -36
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/handler/webrick.rb +0 -129
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/handler.rb +0 -104
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/head.rb +0 -25
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/lint.rb +0 -806
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/lobster.rb +0 -70
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/lock.rb +0 -32
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/logger.rb +0 -20
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/media_type.rb +0 -43
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/method_override.rb +0 -52
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/mime.rb +0 -685
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/mock.rb +0 -273
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/multipart/generator.rb +0 -97
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/multipart/parser.rb +0 -365
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/multipart/uploaded_file.rb +0 -41
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/multipart.rb +0 -64
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/null_logger.rb +0 -39
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/query_parser.rb +0 -221
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/recursive.rb +0 -64
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/reloader.rb +0 -114
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/request.rb +0 -659
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/response.rb +0 -318
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/rewindable_input.rb +0 -94
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/runtime.rb +0 -34
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/sendfile.rb +0 -162
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/server.rb +0 -466
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/session/abstract/id.rb +0 -523
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/session/cookie.rb +0 -203
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/session/memcache.rb +0 -10
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/session/pool.rb +0 -85
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/show_exceptions.rb +0 -390
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/show_status.rb +0 -113
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/static.rb +0 -187
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/tempfile_reaper.rb +0 -22
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/urlmap.rb +0 -97
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/utils.rb +0 -616
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack/version.rb +0 -29
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/lib/rack.rb +0 -141
- data/vendor/bundle/ruby/3.0.0/gems/rack-2.2.4/rack.gemspec +0 -46
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/History.rdoc +0 -2403
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/MIT-LICENSE +0 -21
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/README.rdoc +0 -155
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/doc/command_line_usage.rdoc +0 -158
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/doc/example/Rakefile1 +0 -38
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/doc/example/Rakefile2 +0 -35
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/doc/example/a.c +0 -6
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/doc/example/b.c +0 -6
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/doc/example/main.c +0 -11
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/doc/glossary.rdoc +0 -42
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/doc/jamis.rb +0 -592
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/doc/proto_rake.rdoc +0 -127
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/doc/rake.1 +0 -156
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/doc/rakefile.rdoc +0 -622
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/doc/rational.rdoc +0 -151
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/exe/rake +0 -27
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/application.rb +0 -831
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/backtrace.rb +0 -24
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/clean.rb +0 -78
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/cloneable.rb +0 -17
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/cpu_counter.rb +0 -107
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/default_loader.rb +0 -15
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/dsl_definition.rb +0 -195
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/early_time.rb +0 -22
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/ext/core.rb +0 -26
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/ext/string.rb +0 -176
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/file_creation_task.rb +0 -25
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/file_list.rb +0 -435
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/file_task.rb +0 -54
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/file_utils.rb +0 -134
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/file_utils_ext.rb +0 -134
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/invocation_chain.rb +0 -57
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/invocation_exception_mixin.rb +0 -17
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/late_time.rb +0 -18
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/linked_list.rb +0 -112
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/loaders/makefile.rb +0 -54
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/multi_task.rb +0 -14
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/name_space.rb +0 -38
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/packagetask.rb +0 -222
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/phony.rb +0 -16
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/private_reader.rb +0 -21
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/promise.rb +0 -100
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/pseudo_status.rb +0 -30
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/rake_module.rb +0 -67
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb +0 -27
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/rule_recursion_overflow_error.rb +0 -20
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/scope.rb +0 -43
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/task.rb +0 -434
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/task_argument_error.rb +0 -8
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/task_arguments.rb +0 -109
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/task_manager.rb +0 -331
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/tasklib.rb +0 -12
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/testtask.rb +0 -189
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/thread_history_display.rb +0 -49
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/thread_pool.rb +0 -163
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/trace_output.rb +0 -23
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/version.rb +0 -10
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake/win32.rb +0 -51
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/lib/rake.rb +0 -71
- data/vendor/bundle/ruby/3.0.0/gems/rake-13.0.6/rake.gemspec +0 -100
- data/vendor/bundle/ruby/3.0.0/specifications/rack-2.2.4.gemspec +0 -41
- data/vendor/bundle/ruby/3.0.0/specifications/rake-13.0.6.gemspec +0 -26
@@ -1,153 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Rack
|
4
|
-
### This middleware provides hooks to certain places in the request /
|
5
|
-
# response lifecycle. This is so that middleware that don't need to filter
|
6
|
-
# the response data can safely leave it alone and not have to send messages
|
7
|
-
# down the traditional "rack stack".
|
8
|
-
#
|
9
|
-
# The events are:
|
10
|
-
#
|
11
|
-
# * on_start(request, response)
|
12
|
-
#
|
13
|
-
# This event is sent at the start of the request, before the next
|
14
|
-
# middleware in the chain is called. This method is called with a request
|
15
|
-
# object, and a response object. Right now, the response object is always
|
16
|
-
# nil, but in the future it may actually be a real response object.
|
17
|
-
#
|
18
|
-
# * on_commit(request, response)
|
19
|
-
#
|
20
|
-
# The response has been committed. The application has returned, but the
|
21
|
-
# response has not been sent to the webserver yet. This method is always
|
22
|
-
# called with a request object and the response object. The response
|
23
|
-
# object is constructed from the rack triple that the application returned.
|
24
|
-
# Changes may still be made to the response object at this point.
|
25
|
-
#
|
26
|
-
# * on_send(request, response)
|
27
|
-
#
|
28
|
-
# The webserver has started iterating over the response body and presumably
|
29
|
-
# has started sending data over the wire. This method is always called with
|
30
|
-
# a request object and the response object. The response object is
|
31
|
-
# constructed from the rack triple that the application returned. Changes
|
32
|
-
# SHOULD NOT be made to the response object as the webserver has already
|
33
|
-
# started sending data. Any mutations will likely result in an exception.
|
34
|
-
#
|
35
|
-
# * on_finish(request, response)
|
36
|
-
#
|
37
|
-
# The webserver has closed the response, and all data has been written to
|
38
|
-
# the response socket. The request and response object should both be
|
39
|
-
# read-only at this point. The body MAY NOT be available on the response
|
40
|
-
# object as it may have been flushed to the socket.
|
41
|
-
#
|
42
|
-
# * on_error(request, response, error)
|
43
|
-
#
|
44
|
-
# An exception has occurred in the application or an `on_commit` event.
|
45
|
-
# This method will get the request, the response (if available) and the
|
46
|
-
# exception that was raised.
|
47
|
-
#
|
48
|
-
# ## Order
|
49
|
-
#
|
50
|
-
# `on_start` is called on the handlers in the order that they were passed to
|
51
|
-
# the constructor. `on_commit`, on_send`, `on_finish`, and `on_error` are
|
52
|
-
# called in the reverse order. `on_finish` handlers are called inside an
|
53
|
-
# `ensure` block, so they are guaranteed to be called even if something
|
54
|
-
# raises an exception. If something raises an exception in a `on_finish`
|
55
|
-
# method, then nothing is guaranteed.
|
56
|
-
|
57
|
-
class Events
|
58
|
-
module Abstract
|
59
|
-
def on_start(req, res)
|
60
|
-
end
|
61
|
-
|
62
|
-
def on_commit(req, res)
|
63
|
-
end
|
64
|
-
|
65
|
-
def on_send(req, res)
|
66
|
-
end
|
67
|
-
|
68
|
-
def on_finish(req, res)
|
69
|
-
end
|
70
|
-
|
71
|
-
def on_error(req, res, e)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
class EventedBodyProxy < Rack::BodyProxy # :nodoc:
|
76
|
-
attr_reader :request, :response
|
77
|
-
|
78
|
-
def initialize(body, request, response, handlers, &block)
|
79
|
-
super(body, &block)
|
80
|
-
@request = request
|
81
|
-
@response = response
|
82
|
-
@handlers = handlers
|
83
|
-
end
|
84
|
-
|
85
|
-
def each
|
86
|
-
@handlers.reverse_each { |handler| handler.on_send request, response }
|
87
|
-
super
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
class BufferedResponse < Rack::Response::Raw # :nodoc:
|
92
|
-
attr_reader :body
|
93
|
-
|
94
|
-
def initialize(status, headers, body)
|
95
|
-
super(status, headers)
|
96
|
-
@body = body
|
97
|
-
end
|
98
|
-
|
99
|
-
def to_a; [status, headers, body]; end
|
100
|
-
end
|
101
|
-
|
102
|
-
def initialize(app, handlers)
|
103
|
-
@app = app
|
104
|
-
@handlers = handlers
|
105
|
-
end
|
106
|
-
|
107
|
-
def call(env)
|
108
|
-
request = make_request env
|
109
|
-
on_start request, nil
|
110
|
-
|
111
|
-
begin
|
112
|
-
status, headers, body = @app.call request.env
|
113
|
-
response = make_response status, headers, body
|
114
|
-
on_commit request, response
|
115
|
-
rescue StandardError => e
|
116
|
-
on_error request, response, e
|
117
|
-
on_finish request, response
|
118
|
-
raise
|
119
|
-
end
|
120
|
-
|
121
|
-
body = EventedBodyProxy.new(body, request, response, @handlers) do
|
122
|
-
on_finish request, response
|
123
|
-
end
|
124
|
-
[response.status, response.headers, body]
|
125
|
-
end
|
126
|
-
|
127
|
-
private
|
128
|
-
|
129
|
-
def on_error(request, response, e)
|
130
|
-
@handlers.reverse_each { |handler| handler.on_error request, response, e }
|
131
|
-
end
|
132
|
-
|
133
|
-
def on_commit(request, response)
|
134
|
-
@handlers.reverse_each { |handler| handler.on_commit request, response }
|
135
|
-
end
|
136
|
-
|
137
|
-
def on_start(request, response)
|
138
|
-
@handlers.each { |handler| handler.on_start request, nil }
|
139
|
-
end
|
140
|
-
|
141
|
-
def on_finish(request, response)
|
142
|
-
@handlers.reverse_each { |handler| handler.on_finish request, response }
|
143
|
-
end
|
144
|
-
|
145
|
-
def make_request(env)
|
146
|
-
Rack::Request.new env
|
147
|
-
end
|
148
|
-
|
149
|
-
def make_response(status, headers, body)
|
150
|
-
BufferedResponse.new status, headers, body
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
@@ -1,218 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'time'
|
4
|
-
|
5
|
-
module Rack
|
6
|
-
# Rack::Files serves files below the +root+ directory given, according to the
|
7
|
-
# path info of the Rack request.
|
8
|
-
# e.g. when Rack::Files.new("/etc") is used, you can access 'passwd' file
|
9
|
-
# as http://localhost:9292/passwd
|
10
|
-
#
|
11
|
-
# Handlers can detect if bodies are a Rack::Files, and use mechanisms
|
12
|
-
# like sendfile on the +path+.
|
13
|
-
|
14
|
-
class Files
|
15
|
-
ALLOWED_VERBS = %w[GET HEAD OPTIONS]
|
16
|
-
ALLOW_HEADER = ALLOWED_VERBS.join(', ')
|
17
|
-
MULTIPART_BOUNDARY = 'AaB03x'
|
18
|
-
|
19
|
-
# @todo remove in 3.0
|
20
|
-
def self.method_added(name)
|
21
|
-
if name == :response_body
|
22
|
-
raise "#{self.class}\#response_body is no longer supported."
|
23
|
-
end
|
24
|
-
super
|
25
|
-
end
|
26
|
-
|
27
|
-
attr_reader :root
|
28
|
-
|
29
|
-
def initialize(root, headers = {}, default_mime = 'text/plain')
|
30
|
-
@root = (::File.expand_path(root) if root)
|
31
|
-
@headers = headers
|
32
|
-
@default_mime = default_mime
|
33
|
-
@head = Rack::Head.new(lambda { |env| get env })
|
34
|
-
end
|
35
|
-
|
36
|
-
def call(env)
|
37
|
-
# HEAD requests drop the response body, including 4xx error messages.
|
38
|
-
@head.call env
|
39
|
-
end
|
40
|
-
|
41
|
-
def get(env)
|
42
|
-
request = Rack::Request.new env
|
43
|
-
unless ALLOWED_VERBS.include? request.request_method
|
44
|
-
return fail(405, "Method Not Allowed", { 'Allow' => ALLOW_HEADER })
|
45
|
-
end
|
46
|
-
|
47
|
-
path_info = Utils.unescape_path request.path_info
|
48
|
-
return fail(400, "Bad Request") unless Utils.valid_path?(path_info)
|
49
|
-
|
50
|
-
clean_path_info = Utils.clean_path_info(path_info)
|
51
|
-
path = ::File.join(@root, clean_path_info)
|
52
|
-
|
53
|
-
available = begin
|
54
|
-
::File.file?(path) && ::File.readable?(path)
|
55
|
-
rescue SystemCallError
|
56
|
-
# Not sure in what conditions this exception can occur, but this
|
57
|
-
# is a safe way to handle such an error.
|
58
|
-
# :nocov:
|
59
|
-
false
|
60
|
-
# :nocov:
|
61
|
-
end
|
62
|
-
|
63
|
-
if available
|
64
|
-
serving(request, path)
|
65
|
-
else
|
66
|
-
fail(404, "File not found: #{path_info}")
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def serving(request, path)
|
71
|
-
if request.options?
|
72
|
-
return [200, { 'Allow' => ALLOW_HEADER, CONTENT_LENGTH => '0' }, []]
|
73
|
-
end
|
74
|
-
last_modified = ::File.mtime(path).httpdate
|
75
|
-
return [304, {}, []] if request.get_header('HTTP_IF_MODIFIED_SINCE') == last_modified
|
76
|
-
|
77
|
-
headers = { "Last-Modified" => last_modified }
|
78
|
-
mime_type = mime_type path, @default_mime
|
79
|
-
headers[CONTENT_TYPE] = mime_type if mime_type
|
80
|
-
|
81
|
-
# Set custom headers
|
82
|
-
headers.merge!(@headers) if @headers
|
83
|
-
|
84
|
-
status = 200
|
85
|
-
size = filesize path
|
86
|
-
|
87
|
-
ranges = Rack::Utils.get_byte_ranges(request.get_header('HTTP_RANGE'), size)
|
88
|
-
if ranges.nil?
|
89
|
-
# No ranges:
|
90
|
-
ranges = [0..size - 1]
|
91
|
-
elsif ranges.empty?
|
92
|
-
# Unsatisfiable. Return error, and file size:
|
93
|
-
response = fail(416, "Byte range unsatisfiable")
|
94
|
-
response[1]["Content-Range"] = "bytes */#{size}"
|
95
|
-
return response
|
96
|
-
elsif ranges.size >= 1
|
97
|
-
# Partial content
|
98
|
-
partial_content = true
|
99
|
-
|
100
|
-
if ranges.size == 1
|
101
|
-
range = ranges[0]
|
102
|
-
headers["Content-Range"] = "bytes #{range.begin}-#{range.end}/#{size}"
|
103
|
-
else
|
104
|
-
headers[CONTENT_TYPE] = "multipart/byteranges; boundary=#{MULTIPART_BOUNDARY}"
|
105
|
-
end
|
106
|
-
|
107
|
-
status = 206
|
108
|
-
body = BaseIterator.new(path, ranges, mime_type: mime_type, size: size)
|
109
|
-
size = body.bytesize
|
110
|
-
end
|
111
|
-
|
112
|
-
headers[CONTENT_LENGTH] = size.to_s
|
113
|
-
|
114
|
-
if request.head?
|
115
|
-
body = []
|
116
|
-
elsif !partial_content
|
117
|
-
body = Iterator.new(path, ranges, mime_type: mime_type, size: size)
|
118
|
-
end
|
119
|
-
|
120
|
-
[status, headers, body]
|
121
|
-
end
|
122
|
-
|
123
|
-
class BaseIterator
|
124
|
-
attr_reader :path, :ranges, :options
|
125
|
-
|
126
|
-
def initialize(path, ranges, options)
|
127
|
-
@path = path
|
128
|
-
@ranges = ranges
|
129
|
-
@options = options
|
130
|
-
end
|
131
|
-
|
132
|
-
def each
|
133
|
-
::File.open(path, "rb") do |file|
|
134
|
-
ranges.each do |range|
|
135
|
-
yield multipart_heading(range) if multipart?
|
136
|
-
|
137
|
-
each_range_part(file, range) do |part|
|
138
|
-
yield part
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
yield "\r\n--#{MULTIPART_BOUNDARY}--\r\n" if multipart?
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
def bytesize
|
147
|
-
size = ranges.inject(0) do |sum, range|
|
148
|
-
sum += multipart_heading(range).bytesize if multipart?
|
149
|
-
sum += range.size
|
150
|
-
end
|
151
|
-
size += "\r\n--#{MULTIPART_BOUNDARY}--\r\n".bytesize if multipart?
|
152
|
-
size
|
153
|
-
end
|
154
|
-
|
155
|
-
def close; end
|
156
|
-
|
157
|
-
private
|
158
|
-
|
159
|
-
def multipart?
|
160
|
-
ranges.size > 1
|
161
|
-
end
|
162
|
-
|
163
|
-
def multipart_heading(range)
|
164
|
-
<<-EOF
|
165
|
-
\r
|
166
|
-
--#{MULTIPART_BOUNDARY}\r
|
167
|
-
Content-Type: #{options[:mime_type]}\r
|
168
|
-
Content-Range: bytes #{range.begin}-#{range.end}/#{options[:size]}\r
|
169
|
-
\r
|
170
|
-
EOF
|
171
|
-
end
|
172
|
-
|
173
|
-
def each_range_part(file, range)
|
174
|
-
file.seek(range.begin)
|
175
|
-
remaining_len = range.end - range.begin + 1
|
176
|
-
while remaining_len > 0
|
177
|
-
part = file.read([8192, remaining_len].min)
|
178
|
-
break unless part
|
179
|
-
remaining_len -= part.length
|
180
|
-
|
181
|
-
yield part
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
class Iterator < BaseIterator
|
187
|
-
alias :to_path :path
|
188
|
-
end
|
189
|
-
|
190
|
-
private
|
191
|
-
|
192
|
-
def fail(status, body, headers = {})
|
193
|
-
body += "\n"
|
194
|
-
|
195
|
-
[
|
196
|
-
status,
|
197
|
-
{
|
198
|
-
CONTENT_TYPE => "text/plain",
|
199
|
-
CONTENT_LENGTH => body.size.to_s,
|
200
|
-
"X-Cascade" => "pass"
|
201
|
-
}.merge!(headers),
|
202
|
-
[body]
|
203
|
-
]
|
204
|
-
end
|
205
|
-
|
206
|
-
# The MIME type for the contents of the file located at @path
|
207
|
-
def mime_type(path, default_mime)
|
208
|
-
Mime.mime_type(::File.extname(path), default_mime)
|
209
|
-
end
|
210
|
-
|
211
|
-
def filesize(path)
|
212
|
-
# We check via File::size? whether this file provides size info
|
213
|
-
# via stat (e.g. /proc files often don't), otherwise we have to
|
214
|
-
# figure it out by reading the whole file into memory.
|
215
|
-
::File.size?(path) || ::File.read(path).bytesize
|
216
|
-
end
|
217
|
-
end
|
218
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Rack
|
4
|
-
module Handler
|
5
|
-
class CGI
|
6
|
-
def self.run(app, **options)
|
7
|
-
$stdin.binmode
|
8
|
-
serve app
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.serve(app)
|
12
|
-
env = ENV.to_hash
|
13
|
-
env.delete "HTTP_CONTENT_LENGTH"
|
14
|
-
|
15
|
-
env[SCRIPT_NAME] = "" if env[SCRIPT_NAME] == "/"
|
16
|
-
|
17
|
-
env.update(
|
18
|
-
RACK_VERSION => Rack::VERSION,
|
19
|
-
RACK_INPUT => Rack::RewindableInput.new($stdin),
|
20
|
-
RACK_ERRORS => $stderr,
|
21
|
-
RACK_MULTITHREAD => false,
|
22
|
-
RACK_MULTIPROCESS => true,
|
23
|
-
RACK_RUNONCE => true,
|
24
|
-
RACK_URL_SCHEME => ["yes", "on", "1"].include?(ENV[HTTPS]) ? "https" : "http"
|
25
|
-
)
|
26
|
-
|
27
|
-
env[QUERY_STRING] ||= ""
|
28
|
-
env[HTTP_VERSION] ||= env[SERVER_PROTOCOL]
|
29
|
-
env[REQUEST_PATH] ||= "/"
|
30
|
-
|
31
|
-
status, headers, body = app.call(env)
|
32
|
-
begin
|
33
|
-
send_headers status, headers
|
34
|
-
send_body body
|
35
|
-
ensure
|
36
|
-
body.close if body.respond_to? :close
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.send_headers(status, headers)
|
41
|
-
$stdout.print "Status: #{status}\r\n"
|
42
|
-
headers.each { |k, vs|
|
43
|
-
vs.split("\n").each { |v|
|
44
|
-
$stdout.print "#{k}: #{v}\r\n"
|
45
|
-
}
|
46
|
-
}
|
47
|
-
$stdout.print "\r\n"
|
48
|
-
$stdout.flush
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.send_body(body)
|
52
|
-
body.each { |part|
|
53
|
-
$stdout.print part
|
54
|
-
$stdout.flush
|
55
|
-
}
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'fcgi'
|
4
|
-
require 'socket'
|
5
|
-
|
6
|
-
if defined? FCGI::Stream
|
7
|
-
class FCGI::Stream
|
8
|
-
alias _rack_read_without_buffer read
|
9
|
-
|
10
|
-
def read(n, buffer = nil)
|
11
|
-
buf = _rack_read_without_buffer n
|
12
|
-
buffer.replace(buf.to_s) if buffer
|
13
|
-
buf
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
module Rack
|
19
|
-
module Handler
|
20
|
-
class FastCGI
|
21
|
-
def self.run(app, **options)
|
22
|
-
if options[:File]
|
23
|
-
STDIN.reopen(UNIXServer.new(options[:File]))
|
24
|
-
elsif options[:Port]
|
25
|
-
STDIN.reopen(TCPServer.new(options[:Host], options[:Port]))
|
26
|
-
end
|
27
|
-
FCGI.each { |request|
|
28
|
-
serve request, app
|
29
|
-
}
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.valid_options
|
33
|
-
environment = ENV['RACK_ENV'] || 'development'
|
34
|
-
default_host = environment == 'development' ? 'localhost' : '0.0.0.0'
|
35
|
-
|
36
|
-
{
|
37
|
-
"Host=HOST" => "Hostname to listen on (default: #{default_host})",
|
38
|
-
"Port=PORT" => "Port to listen on (default: 8080)",
|
39
|
-
"File=PATH" => "Creates a Domain socket at PATH instead of a TCP socket. Ignores Host and Port if set.",
|
40
|
-
}
|
41
|
-
end
|
42
|
-
|
43
|
-
def self.serve(request, app)
|
44
|
-
env = request.env
|
45
|
-
env.delete "HTTP_CONTENT_LENGTH"
|
46
|
-
|
47
|
-
env[SCRIPT_NAME] = "" if env[SCRIPT_NAME] == "/"
|
48
|
-
|
49
|
-
rack_input = RewindableInput.new(request.in)
|
50
|
-
|
51
|
-
env.update(
|
52
|
-
RACK_VERSION => Rack::VERSION,
|
53
|
-
RACK_INPUT => rack_input,
|
54
|
-
RACK_ERRORS => request.err,
|
55
|
-
RACK_MULTITHREAD => false,
|
56
|
-
RACK_MULTIPROCESS => true,
|
57
|
-
RACK_RUNONCE => false,
|
58
|
-
RACK_URL_SCHEME => ["yes", "on", "1"].include?(env[HTTPS]) ? "https" : "http"
|
59
|
-
)
|
60
|
-
|
61
|
-
env[QUERY_STRING] ||= ""
|
62
|
-
env[HTTP_VERSION] ||= env[SERVER_PROTOCOL]
|
63
|
-
env[REQUEST_PATH] ||= "/"
|
64
|
-
env.delete "CONTENT_TYPE" if env["CONTENT_TYPE"] == ""
|
65
|
-
env.delete "CONTENT_LENGTH" if env["CONTENT_LENGTH"] == ""
|
66
|
-
|
67
|
-
begin
|
68
|
-
status, headers, body = app.call(env)
|
69
|
-
begin
|
70
|
-
send_headers request.out, status, headers
|
71
|
-
send_body request.out, body
|
72
|
-
ensure
|
73
|
-
body.close if body.respond_to? :close
|
74
|
-
end
|
75
|
-
ensure
|
76
|
-
rack_input.close
|
77
|
-
request.finish
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def self.send_headers(out, status, headers)
|
82
|
-
out.print "Status: #{status}\r\n"
|
83
|
-
headers.each { |k, vs|
|
84
|
-
vs.split("\n").each { |v|
|
85
|
-
out.print "#{k}: #{v}\r\n"
|
86
|
-
}
|
87
|
-
}
|
88
|
-
out.print "\r\n"
|
89
|
-
out.flush
|
90
|
-
end
|
91
|
-
|
92
|
-
def self.send_body(out, body)
|
93
|
-
body.each { |part|
|
94
|
-
out.print part
|
95
|
-
out.flush
|
96
|
-
}
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'lsapi'
|
4
|
-
|
5
|
-
module Rack
|
6
|
-
module Handler
|
7
|
-
class LSWS
|
8
|
-
def self.run(app, **options)
|
9
|
-
while LSAPI.accept != nil
|
10
|
-
serve app
|
11
|
-
end
|
12
|
-
end
|
13
|
-
def self.serve(app)
|
14
|
-
env = ENV.to_hash
|
15
|
-
env.delete "HTTP_CONTENT_LENGTH"
|
16
|
-
env[SCRIPT_NAME] = "" if env[SCRIPT_NAME] == "/"
|
17
|
-
|
18
|
-
rack_input = RewindableInput.new($stdin.read.to_s)
|
19
|
-
|
20
|
-
env.update(
|
21
|
-
RACK_VERSION => Rack::VERSION,
|
22
|
-
RACK_INPUT => rack_input,
|
23
|
-
RACK_ERRORS => $stderr,
|
24
|
-
RACK_MULTITHREAD => false,
|
25
|
-
RACK_MULTIPROCESS => true,
|
26
|
-
RACK_RUNONCE => false,
|
27
|
-
RACK_URL_SCHEME => ["yes", "on", "1"].include?(ENV[HTTPS]) ? "https" : "http"
|
28
|
-
)
|
29
|
-
|
30
|
-
env[QUERY_STRING] ||= ""
|
31
|
-
env[HTTP_VERSION] ||= env[SERVER_PROTOCOL]
|
32
|
-
env[REQUEST_PATH] ||= "/"
|
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
|
-
ensure
|
41
|
-
rack_input.close
|
42
|
-
end
|
43
|
-
def self.send_headers(status, headers)
|
44
|
-
print "Status: #{status}\r\n"
|
45
|
-
headers.each { |k, vs|
|
46
|
-
vs.split("\n").each { |v|
|
47
|
-
print "#{k}: #{v}\r\n"
|
48
|
-
}
|
49
|
-
}
|
50
|
-
print "\r\n"
|
51
|
-
STDOUT.flush
|
52
|
-
end
|
53
|
-
def self.send_body(body)
|
54
|
-
body.each { |part|
|
55
|
-
print part
|
56
|
-
STDOUT.flush
|
57
|
-
}
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'scgi'
|
4
|
-
require 'stringio'
|
5
|
-
|
6
|
-
module Rack
|
7
|
-
module Handler
|
8
|
-
class SCGI < ::SCGI::Processor
|
9
|
-
attr_accessor :app
|
10
|
-
|
11
|
-
def self.run(app, **options)
|
12
|
-
options[:Socket] = UNIXServer.new(options[:File]) if options[:File]
|
13
|
-
new(options.merge(app: app,
|
14
|
-
host: options[:Host],
|
15
|
-
port: options[:Port],
|
16
|
-
socket: options[:Socket])).listen
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.valid_options
|
20
|
-
environment = ENV['RACK_ENV'] || 'development'
|
21
|
-
default_host = environment == 'development' ? 'localhost' : '0.0.0.0'
|
22
|
-
|
23
|
-
{
|
24
|
-
"Host=HOST" => "Hostname to listen on (default: #{default_host})",
|
25
|
-
"Port=PORT" => "Port to listen on (default: 8080)",
|
26
|
-
}
|
27
|
-
end
|
28
|
-
|
29
|
-
def initialize(settings = {})
|
30
|
-
@app = settings[:app]
|
31
|
-
super(settings)
|
32
|
-
end
|
33
|
-
|
34
|
-
def process_request(request, input_body, socket)
|
35
|
-
env = Hash[request]
|
36
|
-
env.delete "HTTP_CONTENT_TYPE"
|
37
|
-
env.delete "HTTP_CONTENT_LENGTH"
|
38
|
-
env[REQUEST_PATH], env[QUERY_STRING] = env["REQUEST_URI"].split('?', 2)
|
39
|
-
env[HTTP_VERSION] ||= env[SERVER_PROTOCOL]
|
40
|
-
env[PATH_INFO] = env[REQUEST_PATH]
|
41
|
-
env[QUERY_STRING] ||= ""
|
42
|
-
env[SCRIPT_NAME] = ""
|
43
|
-
|
44
|
-
rack_input = StringIO.new(input_body)
|
45
|
-
rack_input.set_encoding(Encoding::BINARY)
|
46
|
-
|
47
|
-
env.update(
|
48
|
-
RACK_VERSION => Rack::VERSION,
|
49
|
-
RACK_INPUT => rack_input,
|
50
|
-
RACK_ERRORS => $stderr,
|
51
|
-
RACK_MULTITHREAD => true,
|
52
|
-
RACK_MULTIPROCESS => true,
|
53
|
-
RACK_RUNONCE => false,
|
54
|
-
RACK_URL_SCHEME => ["yes", "on", "1"].include?(env[HTTPS]) ? "https" : "http"
|
55
|
-
)
|
56
|
-
|
57
|
-
status, headers, body = app.call(env)
|
58
|
-
begin
|
59
|
-
socket.write("Status: #{status}\r\n")
|
60
|
-
headers.each do |k, vs|
|
61
|
-
vs.split("\n").each { |v| socket.write("#{k}: #{v}\r\n")}
|
62
|
-
end
|
63
|
-
socket.write("\r\n")
|
64
|
-
body.each {|s| socket.write(s)}
|
65
|
-
ensure
|
66
|
-
body.close if body.respond_to? :close
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "thin"
|
4
|
-
require "thin/server"
|
5
|
-
require "thin/logging"
|
6
|
-
require "thin/backends/tcp_server"
|
7
|
-
|
8
|
-
module Rack
|
9
|
-
module Handler
|
10
|
-
class Thin
|
11
|
-
def self.run(app, **options)
|
12
|
-
environment = ENV['RACK_ENV'] || 'development'
|
13
|
-
default_host = environment == 'development' ? 'localhost' : '0.0.0.0'
|
14
|
-
|
15
|
-
host = options.delete(:Host) || default_host
|
16
|
-
port = options.delete(:Port) || 8080
|
17
|
-
args = [host, port, app, options]
|
18
|
-
# Thin versions below 0.8.0 do not support additional options
|
19
|
-
args.pop if ::Thin::VERSION::MAJOR < 1 && ::Thin::VERSION::MINOR < 8
|
20
|
-
server = ::Thin::Server.new(*args)
|
21
|
-
yield server if block_given?
|
22
|
-
server.start
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.valid_options
|
26
|
-
environment = ENV['RACK_ENV'] || 'development'
|
27
|
-
default_host = environment == 'development' ? 'localhost' : '0.0.0.0'
|
28
|
-
|
29
|
-
{
|
30
|
-
"Host=HOST" => "Hostname to listen on (default: #{default_host})",
|
31
|
-
"Port=PORT" => "Port to listen on (default: 8080)",
|
32
|
-
}
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|