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,83 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Rack
|
4
|
-
# Rack::CommonLogger forwards every request to the given +app+, and
|
5
|
-
# logs a line in the
|
6
|
-
# {Apache common log format}[http://httpd.apache.org/docs/1.3/logs.html#common]
|
7
|
-
# to the configured logger.
|
8
|
-
class CommonLogger
|
9
|
-
# Common Log Format: http://httpd.apache.org/docs/1.3/logs.html#common
|
10
|
-
#
|
11
|
-
# lilith.local - - [07/Aug/2006 23:58:02 -0400] "GET / HTTP/1.1" 500 -
|
12
|
-
#
|
13
|
-
# %{%s - %s [%s] "%s %s%s %s" %d %s\n} %
|
14
|
-
#
|
15
|
-
# The actual format is slightly different than the above due to the
|
16
|
-
# separation of SCRIPT_NAME and PATH_INFO, and because the elapsed
|
17
|
-
# time in seconds is included at the end.
|
18
|
-
FORMAT = %{%s - %s [%s] "%s %s%s%s %s" %d %s %0.4f\n}
|
19
|
-
|
20
|
-
# +logger+ can be any object that supports the +write+ or +<<+ methods,
|
21
|
-
# which includes the standard library Logger. These methods are called
|
22
|
-
# with a single string argument, the log message.
|
23
|
-
# If +logger+ is nil, CommonLogger will fall back <tt>env['rack.errors']</tt>.
|
24
|
-
def initialize(app, logger = nil)
|
25
|
-
@app = app
|
26
|
-
@logger = logger
|
27
|
-
end
|
28
|
-
|
29
|
-
# Log all requests in common_log format after a response has been
|
30
|
-
# returned. Note that if the app raises an exception, the request
|
31
|
-
# will not be logged, so if exception handling middleware are used,
|
32
|
-
# they should be loaded after this middleware. Additionally, because
|
33
|
-
# the logging happens after the request body has been fully sent, any
|
34
|
-
# exceptions raised during the sending of the response body will
|
35
|
-
# cause the request not to be logged.
|
36
|
-
def call(env)
|
37
|
-
began_at = Utils.clock_time
|
38
|
-
status, headers, body = @app.call(env)
|
39
|
-
headers = Utils::HeaderHash[headers]
|
40
|
-
body = BodyProxy.new(body) { log(env, status, headers, began_at) }
|
41
|
-
[status, headers, body]
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
# Log the request to the configured logger.
|
47
|
-
def log(env, status, header, began_at)
|
48
|
-
length = extract_content_length(header)
|
49
|
-
|
50
|
-
msg = FORMAT % [
|
51
|
-
env['HTTP_X_FORWARDED_FOR'] || env["REMOTE_ADDR"] || "-",
|
52
|
-
env["REMOTE_USER"] || "-",
|
53
|
-
Time.now.strftime("%d/%b/%Y:%H:%M:%S %z"),
|
54
|
-
env[REQUEST_METHOD],
|
55
|
-
env[SCRIPT_NAME],
|
56
|
-
env[PATH_INFO],
|
57
|
-
env[QUERY_STRING].empty? ? "" : "?#{env[QUERY_STRING]}",
|
58
|
-
env[SERVER_PROTOCOL],
|
59
|
-
status.to_s[0..3],
|
60
|
-
length,
|
61
|
-
Utils.clock_time - began_at ]
|
62
|
-
|
63
|
-
msg.gsub!(/[^[:print:]\n]/) { |c| "\\x#{c.ord}" }
|
64
|
-
|
65
|
-
logger = @logger || env[RACK_ERRORS]
|
66
|
-
|
67
|
-
# Standard library logger doesn't support write but it supports << which actually
|
68
|
-
# calls to write on the log device without formatting
|
69
|
-
if logger.respond_to?(:write)
|
70
|
-
logger.write(msg)
|
71
|
-
else
|
72
|
-
logger << msg
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Attempt to determine the content length for the response to
|
77
|
-
# include it in the logged data.
|
78
|
-
def extract_content_length(headers)
|
79
|
-
value = headers[CONTENT_LENGTH]
|
80
|
-
!value || value.to_s == '0' ? '-' : value
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Rack
|
4
|
-
|
5
|
-
# Middleware that enables conditional GET using If-None-Match and
|
6
|
-
# If-Modified-Since. The application should set either or both of the
|
7
|
-
# Last-Modified or Etag response headers according to RFC 2616. When
|
8
|
-
# either of the conditions is met, the response body is set to be zero
|
9
|
-
# length and the response status is set to 304 Not Modified.
|
10
|
-
#
|
11
|
-
# Applications that defer response body generation until the body's each
|
12
|
-
# message is received will avoid response body generation completely when
|
13
|
-
# a conditional GET matches.
|
14
|
-
#
|
15
|
-
# Adapted from Michael Klishin's Merb implementation:
|
16
|
-
# https://github.com/wycats/merb/blob/master/merb-core/lib/merb-core/rack/middleware/conditional_get.rb
|
17
|
-
class ConditionalGet
|
18
|
-
def initialize(app)
|
19
|
-
@app = app
|
20
|
-
end
|
21
|
-
|
22
|
-
# Return empty 304 response if the response has not been
|
23
|
-
# modified since the last request.
|
24
|
-
def call(env)
|
25
|
-
case env[REQUEST_METHOD]
|
26
|
-
when "GET", "HEAD"
|
27
|
-
status, headers, body = @app.call(env)
|
28
|
-
headers = Utils::HeaderHash[headers]
|
29
|
-
if status == 200 && fresh?(env, headers)
|
30
|
-
status = 304
|
31
|
-
headers.delete(CONTENT_TYPE)
|
32
|
-
headers.delete(CONTENT_LENGTH)
|
33
|
-
original_body = body
|
34
|
-
body = Rack::BodyProxy.new([]) do
|
35
|
-
original_body.close if original_body.respond_to?(:close)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
[status, headers, body]
|
39
|
-
else
|
40
|
-
@app.call(env)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
# Return whether the response has not been modified since the
|
47
|
-
# last request.
|
48
|
-
def fresh?(env, headers)
|
49
|
-
# If-None-Match has priority over If-Modified-Since per RFC 7232
|
50
|
-
if none_match = env['HTTP_IF_NONE_MATCH']
|
51
|
-
etag_matches?(none_match, headers)
|
52
|
-
elsif (modified_since = env['HTTP_IF_MODIFIED_SINCE']) && (modified_since = to_rfc2822(modified_since))
|
53
|
-
modified_since?(modified_since, headers)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# Whether the ETag response header matches the If-None-Match request header.
|
58
|
-
# If so, the request has not been modified.
|
59
|
-
def etag_matches?(none_match, headers)
|
60
|
-
headers['ETag'] == none_match
|
61
|
-
end
|
62
|
-
|
63
|
-
# Whether the Last-Modified response header matches the If-Modified-Since
|
64
|
-
# request header. If so, the request has not been modified.
|
65
|
-
def modified_since?(modified_since, headers)
|
66
|
-
last_modified = to_rfc2822(headers['Last-Modified']) and
|
67
|
-
modified_since >= last_modified
|
68
|
-
end
|
69
|
-
|
70
|
-
# Return a Time object for the given string (which should be in RFC2822
|
71
|
-
# format), or nil if the string cannot be parsed.
|
72
|
-
def to_rfc2822(since)
|
73
|
-
# shortest possible valid date is the obsolete: 1 Nov 97 09:55 A
|
74
|
-
# anything shorter is invalid, this avoids exceptions for common cases
|
75
|
-
# most common being the empty string
|
76
|
-
if since && since.length >= 16
|
77
|
-
# NOTE: there is no trivial way to write this in a non exception way
|
78
|
-
# _rfc2822 returns a hash but is not that usable
|
79
|
-
Time.rfc2822(since) rescue nil
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Rack
|
4
|
-
# Rack::Config modifies the environment using the block given during
|
5
|
-
# initialization.
|
6
|
-
#
|
7
|
-
# Example:
|
8
|
-
# use Rack::Config do |env|
|
9
|
-
# env['my-key'] = 'some-value'
|
10
|
-
# end
|
11
|
-
class Config
|
12
|
-
def initialize(app, &block)
|
13
|
-
@app = app
|
14
|
-
@block = block
|
15
|
-
end
|
16
|
-
|
17
|
-
def call(env)
|
18
|
-
@block.call(env)
|
19
|
-
@app.call(env)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Rack
|
4
|
-
|
5
|
-
# Sets the Content-Length header on responses that do not specify
|
6
|
-
# a Content-Length or Transfer-Encoding header. Note that this
|
7
|
-
# does not fix responses that have an invalid Content-Length
|
8
|
-
# header specified.
|
9
|
-
class ContentLength
|
10
|
-
include Rack::Utils
|
11
|
-
|
12
|
-
def initialize(app)
|
13
|
-
@app = app
|
14
|
-
end
|
15
|
-
|
16
|
-
def call(env)
|
17
|
-
status, headers, body = @app.call(env)
|
18
|
-
headers = HeaderHash[headers]
|
19
|
-
|
20
|
-
if !STATUS_WITH_NO_ENTITY_BODY.key?(status.to_i) &&
|
21
|
-
!headers[CONTENT_LENGTH] &&
|
22
|
-
!headers[TRANSFER_ENCODING]
|
23
|
-
|
24
|
-
obody = body
|
25
|
-
body, length = [], 0
|
26
|
-
obody.each { |part| body << part; length += part.bytesize }
|
27
|
-
|
28
|
-
body = BodyProxy.new(body) do
|
29
|
-
obody.close if obody.respond_to?(:close)
|
30
|
-
end
|
31
|
-
|
32
|
-
headers[CONTENT_LENGTH] = length.to_s
|
33
|
-
end
|
34
|
-
|
35
|
-
[status, headers, body]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Rack
|
4
|
-
|
5
|
-
# Sets the Content-Type header on responses which don't have one.
|
6
|
-
#
|
7
|
-
# Builder Usage:
|
8
|
-
# use Rack::ContentType, "text/plain"
|
9
|
-
#
|
10
|
-
# When no content type argument is provided, "text/html" is the
|
11
|
-
# default.
|
12
|
-
class ContentType
|
13
|
-
include Rack::Utils
|
14
|
-
|
15
|
-
def initialize(app, content_type = "text/html")
|
16
|
-
@app, @content_type = app, content_type
|
17
|
-
end
|
18
|
-
|
19
|
-
def call(env)
|
20
|
-
status, headers, body = @app.call(env)
|
21
|
-
headers = Utils::HeaderHash[headers]
|
22
|
-
|
23
|
-
unless STATUS_WITH_NO_ENTITY_BODY.key?(status.to_i)
|
24
|
-
headers[CONTENT_TYPE] ||= @content_type
|
25
|
-
end
|
26
|
-
|
27
|
-
[status, headers, body]
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Regexp has `match?` since Ruby 2.4
|
4
|
-
# so to support Ruby < 2.4 we need to define this method
|
5
|
-
|
6
|
-
module Rack
|
7
|
-
module RegexpExtensions
|
8
|
-
refine Regexp do
|
9
|
-
def match?(string, pos = 0)
|
10
|
-
!!match(string, pos)
|
11
|
-
end
|
12
|
-
end unless //.respond_to?(:match?)
|
13
|
-
end
|
14
|
-
end
|
@@ -1,144 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "zlib"
|
4
|
-
require "time" # for Time.httpdate
|
5
|
-
|
6
|
-
module Rack
|
7
|
-
# This middleware enables content encoding of http responses,
|
8
|
-
# usually for purposes of compression.
|
9
|
-
#
|
10
|
-
# Currently supported encodings:
|
11
|
-
#
|
12
|
-
# * gzip
|
13
|
-
# * identity (no transformation)
|
14
|
-
#
|
15
|
-
# This middleware automatically detects when encoding is supported
|
16
|
-
# and allowed. For example no encoding is made when a cache
|
17
|
-
# directive of 'no-transform' is present, when the response status
|
18
|
-
# code is one that doesn't allow an entity body, or when the body
|
19
|
-
# is empty.
|
20
|
-
#
|
21
|
-
# Note that despite the name, Deflater does not support the +deflate+
|
22
|
-
# encoding.
|
23
|
-
class Deflater
|
24
|
-
(require_relative 'core_ext/regexp'; using ::Rack::RegexpExtensions) if RUBY_VERSION < '2.4'
|
25
|
-
|
26
|
-
# Creates Rack::Deflater middleware. Options:
|
27
|
-
#
|
28
|
-
# :if :: a lambda enabling / disabling deflation based on returned boolean value
|
29
|
-
# (e.g <tt>use Rack::Deflater, :if => lambda { |*, body| sum=0; body.each { |i| sum += i.length }; sum > 512 }</tt>).
|
30
|
-
# However, be aware that calling `body.each` inside the block will break cases where `body.each` is not idempotent,
|
31
|
-
# such as when it is an +IO+ instance.
|
32
|
-
# :include :: a list of content types that should be compressed. By default, all content types are compressed.
|
33
|
-
# :sync :: determines if the stream is going to be flushed after every chunk. Flushing after every chunk reduces
|
34
|
-
# latency for time-sensitive streaming applications, but hurts compression and throughput.
|
35
|
-
# Defaults to +true+.
|
36
|
-
def initialize(app, options = {})
|
37
|
-
@app = app
|
38
|
-
@condition = options[:if]
|
39
|
-
@compressible_types = options[:include]
|
40
|
-
@sync = options.fetch(:sync, true)
|
41
|
-
end
|
42
|
-
|
43
|
-
def call(env)
|
44
|
-
status, headers, body = @app.call(env)
|
45
|
-
headers = Utils::HeaderHash[headers]
|
46
|
-
|
47
|
-
unless should_deflate?(env, status, headers, body)
|
48
|
-
return [status, headers, body]
|
49
|
-
end
|
50
|
-
|
51
|
-
request = Request.new(env)
|
52
|
-
|
53
|
-
encoding = Utils.select_best_encoding(%w(gzip identity),
|
54
|
-
request.accept_encoding)
|
55
|
-
|
56
|
-
# Set the Vary HTTP header.
|
57
|
-
vary = headers["Vary"].to_s.split(",").map(&:strip)
|
58
|
-
unless vary.include?("*") || vary.include?("Accept-Encoding")
|
59
|
-
headers["Vary"] = vary.push("Accept-Encoding").join(",")
|
60
|
-
end
|
61
|
-
|
62
|
-
case encoding
|
63
|
-
when "gzip"
|
64
|
-
headers['Content-Encoding'] = "gzip"
|
65
|
-
headers.delete(CONTENT_LENGTH)
|
66
|
-
mtime = headers["Last-Modified"]
|
67
|
-
mtime = Time.httpdate(mtime).to_i if mtime
|
68
|
-
[status, headers, GzipStream.new(body, mtime, @sync)]
|
69
|
-
when "identity"
|
70
|
-
[status, headers, body]
|
71
|
-
when nil
|
72
|
-
message = "An acceptable encoding for the requested resource #{request.fullpath} could not be found."
|
73
|
-
bp = Rack::BodyProxy.new([message]) { body.close if body.respond_to?(:close) }
|
74
|
-
[406, { CONTENT_TYPE => "text/plain", CONTENT_LENGTH => message.length.to_s }, bp]
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
# Body class used for gzip encoded responses.
|
79
|
-
class GzipStream
|
80
|
-
# Initialize the gzip stream. Arguments:
|
81
|
-
# body :: Response body to compress with gzip
|
82
|
-
# mtime :: The modification time of the body, used to set the
|
83
|
-
# modification time in the gzip header.
|
84
|
-
# sync :: Whether to flush each gzip chunk as soon as it is ready.
|
85
|
-
def initialize(body, mtime, sync)
|
86
|
-
@body = body
|
87
|
-
@mtime = mtime
|
88
|
-
@sync = sync
|
89
|
-
end
|
90
|
-
|
91
|
-
# Yield gzip compressed strings to the given block.
|
92
|
-
def each(&block)
|
93
|
-
@writer = block
|
94
|
-
gzip = ::Zlib::GzipWriter.new(self)
|
95
|
-
gzip.mtime = @mtime if @mtime
|
96
|
-
@body.each { |part|
|
97
|
-
# Skip empty strings, as they would result in no output,
|
98
|
-
# and flushing empty parts would raise Zlib::BufError.
|
99
|
-
next if part.empty?
|
100
|
-
|
101
|
-
gzip.write(part)
|
102
|
-
gzip.flush if @sync
|
103
|
-
}
|
104
|
-
ensure
|
105
|
-
gzip.close
|
106
|
-
end
|
107
|
-
|
108
|
-
# Call the block passed to #each with the the gzipped data.
|
109
|
-
def write(data)
|
110
|
-
@writer.call(data)
|
111
|
-
end
|
112
|
-
|
113
|
-
# Close the original body if possible.
|
114
|
-
def close
|
115
|
-
@body.close if @body.respond_to?(:close)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
private
|
120
|
-
|
121
|
-
# Whether the body should be compressed.
|
122
|
-
def should_deflate?(env, status, headers, body)
|
123
|
-
# Skip compressing empty entity body responses and responses with
|
124
|
-
# no-transform set.
|
125
|
-
if Utils::STATUS_WITH_NO_ENTITY_BODY.key?(status.to_i) ||
|
126
|
-
/\bno-transform\b/.match?(headers['Cache-Control'].to_s) ||
|
127
|
-
headers['Content-Encoding']&.!~(/\bidentity\b/)
|
128
|
-
return false
|
129
|
-
end
|
130
|
-
|
131
|
-
# Skip if @compressible_types are given and does not include request's content type
|
132
|
-
return false if @compressible_types && !(headers.has_key?('Content-Type') && @compressible_types.include?(headers['Content-Type'][/[^;]*/]))
|
133
|
-
|
134
|
-
# Skip if @condition lambda is given and evaluates to false
|
135
|
-
return false if @condition && !@condition.call(env, status, headers, body)
|
136
|
-
|
137
|
-
# No point in compressing empty body, also handles usage with
|
138
|
-
# Rack::Sendfile.
|
139
|
-
return false if headers[CONTENT_LENGTH] == '0'
|
140
|
-
|
141
|
-
true
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
@@ -1,199 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'time'
|
4
|
-
|
5
|
-
module Rack
|
6
|
-
# Rack::Directory serves entries below the +root+ given, according to the
|
7
|
-
# path info of the Rack request. If a directory is found, the file's contents
|
8
|
-
# will be presented in an html based index. If a file is found, the env will
|
9
|
-
# be passed to the specified +app+.
|
10
|
-
#
|
11
|
-
# If +app+ is not specified, a Rack::Files of the same +root+ will be used.
|
12
|
-
|
13
|
-
class Directory
|
14
|
-
DIR_FILE = "<tr><td class='name'><a href='%s'>%s</a></td><td class='size'>%s</td><td class='type'>%s</td><td class='mtime'>%s</td></tr>\n"
|
15
|
-
DIR_PAGE_HEADER = <<-PAGE
|
16
|
-
<html><head>
|
17
|
-
<title>%s</title>
|
18
|
-
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
19
|
-
<style type='text/css'>
|
20
|
-
table { width:100%%; }
|
21
|
-
.name { text-align:left; }
|
22
|
-
.size, .mtime { text-align:right; }
|
23
|
-
.type { width:11em; }
|
24
|
-
.mtime { width:15em; }
|
25
|
-
</style>
|
26
|
-
</head><body>
|
27
|
-
<h1>%s</h1>
|
28
|
-
<hr />
|
29
|
-
<table>
|
30
|
-
<tr>
|
31
|
-
<th class='name'>Name</th>
|
32
|
-
<th class='size'>Size</th>
|
33
|
-
<th class='type'>Type</th>
|
34
|
-
<th class='mtime'>Last Modified</th>
|
35
|
-
</tr>
|
36
|
-
PAGE
|
37
|
-
DIR_PAGE_FOOTER = <<-PAGE
|
38
|
-
</table>
|
39
|
-
<hr />
|
40
|
-
</body></html>
|
41
|
-
PAGE
|
42
|
-
|
43
|
-
# Body class for directory entries, showing an index page with links
|
44
|
-
# to each file.
|
45
|
-
class DirectoryBody < Struct.new(:root, :path, :files)
|
46
|
-
# Yield strings for each part of the directory entry
|
47
|
-
def each
|
48
|
-
show_path = Utils.escape_html(path.sub(/^#{root}/, ''))
|
49
|
-
yield(DIR_PAGE_HEADER % [ show_path, show_path ])
|
50
|
-
|
51
|
-
unless path.chomp('/') == root
|
52
|
-
yield(DIR_FILE % DIR_FILE_escape(files.call('..')))
|
53
|
-
end
|
54
|
-
|
55
|
-
Dir.foreach(path) do |basename|
|
56
|
-
next if basename.start_with?('.')
|
57
|
-
next unless f = files.call(basename)
|
58
|
-
yield(DIR_FILE % DIR_FILE_escape(f))
|
59
|
-
end
|
60
|
-
|
61
|
-
yield(DIR_PAGE_FOOTER)
|
62
|
-
end
|
63
|
-
|
64
|
-
private
|
65
|
-
|
66
|
-
# Escape each element in the array of html strings.
|
67
|
-
def DIR_FILE_escape(htmls)
|
68
|
-
htmls.map { |e| Utils.escape_html(e) }
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
# The root of the directory hierarchy. Only requests for files and
|
73
|
-
# directories inside of the root directory are supported.
|
74
|
-
attr_reader :root
|
75
|
-
|
76
|
-
# Set the root directory and application for serving files.
|
77
|
-
def initialize(root, app = nil)
|
78
|
-
@root = ::File.expand_path(root)
|
79
|
-
@app = app || Files.new(@root)
|
80
|
-
@head = Head.new(method(:get))
|
81
|
-
end
|
82
|
-
|
83
|
-
def call(env)
|
84
|
-
# strip body if this is a HEAD call
|
85
|
-
@head.call env
|
86
|
-
end
|
87
|
-
|
88
|
-
# Internals of request handling. Similar to call but does
|
89
|
-
# not remove body for HEAD requests.
|
90
|
-
def get(env)
|
91
|
-
script_name = env[SCRIPT_NAME]
|
92
|
-
path_info = Utils.unescape_path(env[PATH_INFO])
|
93
|
-
|
94
|
-
if client_error_response = check_bad_request(path_info) || check_forbidden(path_info)
|
95
|
-
client_error_response
|
96
|
-
else
|
97
|
-
path = ::File.join(@root, path_info)
|
98
|
-
list_path(env, path, path_info, script_name)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
# Rack response to use for requests with invalid paths, or nil if path is valid.
|
103
|
-
def check_bad_request(path_info)
|
104
|
-
return if Utils.valid_path?(path_info)
|
105
|
-
|
106
|
-
body = "Bad Request\n"
|
107
|
-
[400, { CONTENT_TYPE => "text/plain",
|
108
|
-
CONTENT_LENGTH => body.bytesize.to_s,
|
109
|
-
"X-Cascade" => "pass" }, [body]]
|
110
|
-
end
|
111
|
-
|
112
|
-
# Rack response to use for requests with paths outside the root, or nil if path is inside the root.
|
113
|
-
def check_forbidden(path_info)
|
114
|
-
return unless path_info.include? ".."
|
115
|
-
return if ::File.expand_path(::File.join(@root, path_info)).start_with?(@root)
|
116
|
-
|
117
|
-
body = "Forbidden\n"
|
118
|
-
[403, { CONTENT_TYPE => "text/plain",
|
119
|
-
CONTENT_LENGTH => body.bytesize.to_s,
|
120
|
-
"X-Cascade" => "pass" }, [body]]
|
121
|
-
end
|
122
|
-
|
123
|
-
# Rack response to use for directories under the root.
|
124
|
-
def list_directory(path_info, path, script_name)
|
125
|
-
url_head = (script_name.split('/') + path_info.split('/')).map do |part|
|
126
|
-
Utils.escape_path part
|
127
|
-
end
|
128
|
-
|
129
|
-
# Globbing not safe as path could contain glob metacharacters
|
130
|
-
body = DirectoryBody.new(@root, path, ->(basename) do
|
131
|
-
stat = stat(::File.join(path, basename))
|
132
|
-
next unless stat
|
133
|
-
|
134
|
-
url = ::File.join(*url_head + [Utils.escape_path(basename)])
|
135
|
-
mtime = stat.mtime.httpdate
|
136
|
-
if stat.directory?
|
137
|
-
type = 'directory'
|
138
|
-
size = '-'
|
139
|
-
url << '/'
|
140
|
-
if basename == '..'
|
141
|
-
basename = 'Parent Directory'
|
142
|
-
else
|
143
|
-
basename << '/'
|
144
|
-
end
|
145
|
-
else
|
146
|
-
type = Mime.mime_type(::File.extname(basename))
|
147
|
-
size = filesize_format(stat.size)
|
148
|
-
end
|
149
|
-
|
150
|
-
[ url, basename, size, type, mtime ]
|
151
|
-
end)
|
152
|
-
|
153
|
-
[ 200, { CONTENT_TYPE => 'text/html; charset=utf-8' }, body ]
|
154
|
-
end
|
155
|
-
|
156
|
-
# File::Stat for the given path, but return nil for missing/bad entries.
|
157
|
-
def stat(path)
|
158
|
-
::File.stat(path)
|
159
|
-
rescue Errno::ENOENT, Errno::ELOOP
|
160
|
-
return nil
|
161
|
-
end
|
162
|
-
|
163
|
-
# Rack response to use for files and directories under the root.
|
164
|
-
# Unreadable and non-file, non-directory entries will get a 404 response.
|
165
|
-
def list_path(env, path, path_info, script_name)
|
166
|
-
if (stat = stat(path)) && stat.readable?
|
167
|
-
return @app.call(env) if stat.file?
|
168
|
-
return list_directory(path_info, path, script_name) if stat.directory?
|
169
|
-
end
|
170
|
-
|
171
|
-
entity_not_found(path_info)
|
172
|
-
end
|
173
|
-
|
174
|
-
# Rack response to use for unreadable and non-file, non-directory entries.
|
175
|
-
def entity_not_found(path_info)
|
176
|
-
body = "Entity not found: #{path_info}\n"
|
177
|
-
[404, { CONTENT_TYPE => "text/plain",
|
178
|
-
CONTENT_LENGTH => body.bytesize.to_s,
|
179
|
-
"X-Cascade" => "pass" }, [body]]
|
180
|
-
end
|
181
|
-
|
182
|
-
# Stolen from Ramaze
|
183
|
-
FILESIZE_FORMAT = [
|
184
|
-
['%.1fT', 1 << 40],
|
185
|
-
['%.1fG', 1 << 30],
|
186
|
-
['%.1fM', 1 << 20],
|
187
|
-
['%.1fK', 1 << 10],
|
188
|
-
]
|
189
|
-
|
190
|
-
# Provide human readable file sizes
|
191
|
-
def filesize_format(int)
|
192
|
-
FILESIZE_FORMAT.each do |format, size|
|
193
|
-
return format % (int.to_f / size) if int >= size
|
194
|
-
end
|
195
|
-
|
196
|
-
"#{int}B"
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../rack'
|
4
|
-
require 'digest/sha2'
|
5
|
-
|
6
|
-
module Rack
|
7
|
-
# Automatically sets the ETag header on all String bodies.
|
8
|
-
#
|
9
|
-
# The ETag header is skipped if ETag or Last-Modified headers are sent or if
|
10
|
-
# a sendfile body (body.responds_to :to_path) is given (since such cases
|
11
|
-
# should be handled by apache/nginx).
|
12
|
-
#
|
13
|
-
# On initialization, you can pass two parameters: a Cache-Control directive
|
14
|
-
# used when Etag is absent and a directive when it is present. The first
|
15
|
-
# defaults to nil, while the second defaults to "max-age=0, private, must-revalidate"
|
16
|
-
class ETag
|
17
|
-
ETAG_STRING = Rack::ETAG
|
18
|
-
DEFAULT_CACHE_CONTROL = "max-age=0, private, must-revalidate"
|
19
|
-
|
20
|
-
def initialize(app, no_cache_control = nil, cache_control = DEFAULT_CACHE_CONTROL)
|
21
|
-
@app = app
|
22
|
-
@cache_control = cache_control
|
23
|
-
@no_cache_control = no_cache_control
|
24
|
-
end
|
25
|
-
|
26
|
-
def call(env)
|
27
|
-
status, headers, body = @app.call(env)
|
28
|
-
|
29
|
-
headers = Utils::HeaderHash[headers]
|
30
|
-
|
31
|
-
if etag_status?(status) && etag_body?(body) && !skip_caching?(headers)
|
32
|
-
original_body = body
|
33
|
-
digest, new_body = digest_body(body)
|
34
|
-
body = Rack::BodyProxy.new(new_body) do
|
35
|
-
original_body.close if original_body.respond_to?(:close)
|
36
|
-
end
|
37
|
-
headers[ETAG_STRING] = %(W/"#{digest}") if digest
|
38
|
-
end
|
39
|
-
|
40
|
-
unless headers[CACHE_CONTROL]
|
41
|
-
if digest
|
42
|
-
headers[CACHE_CONTROL] = @cache_control if @cache_control
|
43
|
-
else
|
44
|
-
headers[CACHE_CONTROL] = @no_cache_control if @no_cache_control
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
[status, headers, body]
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
def etag_status?(status)
|
54
|
-
status == 200 || status == 201
|
55
|
-
end
|
56
|
-
|
57
|
-
def etag_body?(body)
|
58
|
-
!body.respond_to?(:to_path)
|
59
|
-
end
|
60
|
-
|
61
|
-
def skip_caching?(headers)
|
62
|
-
headers.key?(ETAG_STRING) || headers.key?('Last-Modified')
|
63
|
-
end
|
64
|
-
|
65
|
-
def digest_body(body)
|
66
|
-
parts = []
|
67
|
-
digest = nil
|
68
|
-
|
69
|
-
body.each do |part|
|
70
|
-
parts << part
|
71
|
-
(digest ||= Digest::SHA256.new) << part unless part.empty?
|
72
|
-
end
|
73
|
-
|
74
|
-
[digest && digest.hexdigest.byteslice(0, 32), parts]
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|