roda 3.108.0 → 3.110.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.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/lib/roda/cache.rb +0 -2
  3. data/lib/roda/opts.rb +22 -0
  4. data/lib/roda/plugins/Integer_matcher_max.rb +1 -1
  5. data/lib/roda/plugins/_add_script_name.rb +14 -0
  6. data/lib/roda/plugins/_json.rb +22 -0
  7. data/lib/roda/plugins/_symbol_class_matchers.rb +8 -10
  8. data/lib/roda/plugins/additional_render_engines.rb +5 -1
  9. data/lib/roda/plugins/additional_view_directories.rb +7 -3
  10. data/lib/roda/plugins/assets.rb +179 -151
  11. data/lib/roda/plugins/assets_preloading.rb +26 -10
  12. data/lib/roda/plugins/autoload_hash_branches.rb +9 -3
  13. data/lib/roda/plugins/autoload_named_routes.rb +9 -3
  14. data/lib/roda/plugins/backtracking_array.rb +2 -2
  15. data/lib/roda/plugins/branch_locals.rb +4 -4
  16. data/lib/roda/plugins/break.rb +2 -2
  17. data/lib/roda/plugins/caching.rb +27 -17
  18. data/lib/roda/plugins/capture_erb.rb +19 -12
  19. data/lib/roda/plugins/chunked.rb +42 -34
  20. data/lib/roda/plugins/class_level_routing.rb +10 -5
  21. data/lib/roda/plugins/class_matchers.rb +14 -7
  22. data/lib/roda/plugins/common_logger.rb +27 -5
  23. data/lib/roda/plugins/conditional_sessions.rb +4 -4
  24. data/lib/roda/plugins/content_for.rb +12 -7
  25. data/lib/roda/plugins/content_security_policy.rb +17 -14
  26. data/lib/roda/plugins/cookie_flags.rb +17 -7
  27. data/lib/roda/plugins/cookies.rb +12 -6
  28. data/lib/roda/plugins/csrf.rb +2 -1
  29. data/lib/roda/plugins/custom_block_results.rb +11 -10
  30. data/lib/roda/plugins/custom_matchers.rb +4 -2
  31. data/lib/roda/plugins/default_headers.rb +4 -7
  32. data/lib/roda/plugins/default_status.rb +1 -0
  33. data/lib/roda/plugins/delay_build.rb +1 -1
  34. data/lib/roda/plugins/delegate.rb +7 -6
  35. data/lib/roda/plugins/direct_call.rb +5 -1
  36. data/lib/roda/plugins/disallow_file_uploads.rb +2 -3
  37. data/lib/roda/plugins/drop_body.rb +3 -6
  38. data/lib/roda/plugins/each_part.rb +23 -29
  39. data/lib/roda/plugins/early_hints.rb +4 -4
  40. data/lib/roda/plugins/empty_root.rb +5 -5
  41. data/lib/roda/plugins/environments.rb +11 -15
  42. data/lib/roda/plugins/erb_h.rb +4 -4
  43. data/lib/roda/plugins/error_email.rb +23 -20
  44. data/lib/roda/plugins/error_handler.rb +28 -34
  45. data/lib/roda/plugins/error_mail.rb +31 -16
  46. data/lib/roda/plugins/exception_page.rb +41 -35
  47. data/lib/roda/plugins/filter_common_logger.rb +6 -4
  48. data/lib/roda/plugins/flash.rb +16 -13
  49. data/lib/roda/plugins/freeze_request_response.rb +24 -0
  50. data/lib/roda/plugins/hash_branch_view_subdir.rb +6 -4
  51. data/lib/roda/plugins/hash_branches.rb +7 -5
  52. data/lib/roda/plugins/hash_paths.rb +7 -5
  53. data/lib/roda/plugins/hash_public.rb +11 -7
  54. data/lib/roda/plugins/hash_public_cache.rb +9 -7
  55. data/lib/roda/plugins/hash_routes.rb +6 -4
  56. data/lib/roda/plugins/heartbeat.rb +6 -2
  57. data/lib/roda/plugins/hmac_paths.rb +9 -3
  58. data/lib/roda/plugins/hooks.rb +13 -10
  59. data/lib/roda/plugins/host_authorization.rb +7 -2
  60. data/lib/roda/plugins/host_routing.rb +7 -2
  61. data/lib/roda/plugins/invalid_request_body.rb +20 -4
  62. data/lib/roda/plugins/ip_from_header.rb +5 -1
  63. data/lib/roda/plugins/json.rb +10 -8
  64. data/lib/roda/plugins/json_parser.rb +26 -12
  65. data/lib/roda/plugins/mail_processor.rb +9 -6
  66. data/lib/roda/plugins/mailer.rb +5 -3
  67. data/lib/roda/plugins/match_affix.rb +6 -1
  68. data/lib/roda/plugins/match_hook_args.rb +7 -5
  69. data/lib/roda/plugins/middleware.rb +13 -7
  70. data/lib/roda/plugins/module_include.rb +1 -1
  71. data/lib/roda/plugins/multi_public.rb +6 -2
  72. data/lib/roda/plugins/multi_route.rb +1 -1
  73. data/lib/roda/plugins/multi_run.rb +13 -17
  74. data/lib/roda/plugins/named_routes.rb +8 -6
  75. data/lib/roda/plugins/named_templates.rb +5 -3
  76. data/lib/roda/plugins/path.rb +16 -14
  77. data/lib/roda/plugins/path_rewriter.rb +8 -5
  78. data/lib/roda/plugins/permissions_policy.rb +21 -19
  79. data/lib/roda/plugins/public.rb +22 -10
  80. data/lib/roda/plugins/recheck_precompiled_assets.rb +30 -8
  81. data/lib/roda/plugins/redirect_http_to_https.rb +6 -3
  82. data/lib/roda/plugins/render.rb +37 -49
  83. data/lib/roda/plugins/render_coverage.rb +6 -3
  84. data/lib/roda/plugins/render_locals.rb +13 -7
  85. data/lib/roda/plugins/request_aref.rb +1 -1
  86. data/lib/roda/plugins/response_content_type.rb +7 -3
  87. data/lib/roda/plugins/route_csrf.rb +7 -2
  88. data/lib/roda/plugins/run_append_slash.rb +5 -1
  89. data/lib/roda/plugins/sec_fetch_site_csrf.rb +6 -2
  90. data/lib/roda/plugins/sessions.rb +164 -139
  91. data/lib/roda/plugins/shape_friendly.rb +3 -1
  92. data/lib/roda/plugins/sinatra_helpers.rb +7 -3
  93. data/lib/roda/plugins/status_handler.rb +5 -3
  94. data/lib/roda/plugins/strip_path_prefix.rb +4 -2
  95. data/lib/roda/plugins/symbol_matchers.rb +11 -6
  96. data/lib/roda/plugins/symbol_views.rb +1 -1
  97. data/lib/roda/plugins/timestamp_public.rb +8 -4
  98. data/lib/roda/plugins/type_routing.rb +9 -5
  99. data/lib/roda/plugins/typecast_params.rb +2 -2
  100. data/lib/roda/plugins/typecast_params_sized_integers.rb +1 -1
  101. data/lib/roda/plugins/unescape_path.rb +22 -4
  102. data/lib/roda/plugins/url_escape.rb +2 -14
  103. data/lib/roda/plugins.rb +34 -0
  104. data/lib/roda/request.rb +8 -7
  105. data/lib/roda/response.rb +9 -7
  106. data/lib/roda/version.rb +1 -1
  107. data/lib/roda.rb +37 -23
  108. metadata +7 -3
@@ -256,6 +256,11 @@ class Roda
256
256
  end
257
257
  end
258
258
 
259
+ module ClassMethods
260
+ RodaPlugins.opt_attr_reader(self, :absolute_redirects, name: :absolute_redirects?)
261
+ RodaPlugins.opt_attr_reader(self, :prefixed_redirects, name: :prefixed_redirects?)
262
+ end
263
+
259
264
  module RequestMethods
260
265
  # Alias for referrer
261
266
  def back
@@ -285,9 +290,8 @@ class Roda
285
290
  # If the absolute_redirects or :prefixed_redirects roda class options has been set, respect those
286
291
  # and update the path.
287
292
  def redirect(path=(no_add_script_name = true; default_redirect_path), status=default_redirect_status)
288
- opts = roda_class.opts
289
- absolute_redirects = opts[:absolute_redirects]
290
- prefixed_redirects = no_add_script_name ? false : opts[:prefixed_redirects]
293
+ absolute_redirects = roda_class.absolute_redirects?
294
+ prefixed_redirects = no_add_script_name ? false : roda_class.prefixed_redirects?
291
295
  path = uri(path, absolute_redirects, prefixed_redirects) if absolute_redirects || prefixed_redirects
292
296
  super(path, status)
293
297
  end
@@ -37,6 +37,8 @@ class Roda
37
37
  end
38
38
 
39
39
  module ClassMethods
40
+ RodaPlugins.opt_attr_reader(self, :status_handler, name: :status_handlers)
41
+
40
42
  # Install the given block as a status handler for the given HTTP response code.
41
43
  def status_handler(code, opts=OPTS, &block)
42
44
  # For backwards compatibility, pass request argument if block accepts argument
@@ -54,7 +56,7 @@ class Roda
54
56
  end
55
57
 
56
58
  meth = define_roda_method(:"_roda_status_handler__#{code}", arity, &block)
57
- self.opts[:status_handler][code] = define_roda_method(:"_roda_status_handler_#{code}", 1) do |result|
59
+ status_handlers[code] = define_roda_method(:"_roda_status_handler_#{code}", 1) do |result|
58
60
  res = @_response
59
61
  res.status = result[0]
60
62
  handle_headers.call(res.headers)
@@ -64,7 +66,7 @@ class Roda
64
66
 
65
67
  # Freeze the hash of status handlers so that there can be no thread safety issues at runtime.
66
68
  def freeze
67
- opts[:status_handler].freeze
69
+ status_handlers.freeze
68
70
  super
69
71
  end
70
72
  end
@@ -74,7 +76,7 @@ class Roda
74
76
 
75
77
  # If routing returns a response we have a handler for, call that handler.
76
78
  def _roda_after_20__status_handler(result)
77
- if result && (meth = opts[:status_handler][result[0]]) && (v = result[2]).is_a?(Array) && v.empty?
79
+ if result && (meth = self.class.status_handlers[result[0]]) && (v = result[2]).is_a?(Array) && v.empty?
78
80
  send(meth, result)
79
81
  end
80
82
  end
@@ -21,9 +21,11 @@ class Roda
21
21
  end
22
22
 
23
23
  module ClassMethods
24
+ RodaPlugins.opt_attr_reader(self, :strip_path_prefix, name: :strip_path_prefix_regexp)
25
+
24
26
  # Strip the path prefix from the gien path if it starts with the prefix.
25
- def expand_path(path, root=opts[:root])
26
- super.sub(opts[:strip_path_prefix], '')
27
+ def expand_path(path, root=app_root)
28
+ super.sub(strip_path_prefix_regexp, '')
27
29
  end
28
30
  end
29
31
  end
@@ -19,7 +19,7 @@ class Roda
19
19
  # Then the route will only if the path is +/foobar123+, but not if it is
20
20
  # +/foo+, +/FooBar123+, or +/foobar_123+.
21
21
  #
22
- # You can provide a <tt>segment: true</tt> option to symbol_matcher to speed up
22
+ # You can provide a <tt>segment: true</tt> argument to symbol_matcher to speed up
23
23
  # the matching on Ruby 2.4+:
24
24
  #
25
25
  # symbol_matcher :username, /([a-z0-9]{6,20})/, segment: true
@@ -121,6 +121,8 @@ class Roda
121
121
  end
122
122
 
123
123
  module ClassMethods
124
+ RodaPlugins.opt_attr_reader(self, :symbol_matchers)
125
+
124
126
  # Set the matcher and block to use for the given class.
125
127
  # The matcher can be a regexp, registered symbol matcher, or registered class
126
128
  # matcher (if using the class_matchers plugin).
@@ -129,10 +131,13 @@ class Roda
129
131
  # If providing a registered symbol or class, the block will be called with the
130
132
  # captures returned by the block for the registered symbol or class, or the regexp
131
133
  # captures if no block was registered with the symbol or class. In either case,
132
- # if a block is given, it should return an array with the captures to yield to
133
- # the match block.
134
- def symbol_matcher(s, matcher, opts=OPTS, &block)
135
- _symbol_class_matcher(Symbol, s, matcher, block, opts) do |meth, array|
134
+ # if a block is given, it should return an object to yield to the match block,
135
+ # or an array to yield multiple arguments to the match block. If the block returns
136
+ # nil or false, it will be treated as not matching.
137
+ def symbol_matcher(s, matcher, opts=(no_positional_opts = true; OPTS), segment: opts[:segment], **kw, &block)
138
+ RodaPlugins.check_keywords(__callee__, no_positional_opts, opts, kw)
139
+
140
+ _symbol_class_matcher(Symbol, s, matcher, block, segment: segment) do |meth, array|
136
141
  define_method(meth){array}
137
142
  end
138
143
 
@@ -141,7 +146,7 @@ class Roda
141
146
 
142
147
  # Freeze the class_matchers hash when freezing the app.
143
148
  def freeze
144
- opts[:symbol_matchers].freeze
149
+ symbol_matchers.freeze
145
150
  super
146
151
  end
147
152
  end
@@ -28,7 +28,7 @@ class Roda
28
28
  end
29
29
 
30
30
  def self.configure(app)
31
- app.opts[:custom_block_results][Symbol] = :view
31
+ app.custom_block_results[Symbol] = :view
32
32
  end
33
33
  end
34
34
 
@@ -46,7 +46,11 @@ class Roda
46
46
  #
47
47
  # The options given are also passed to the public plugin.
48
48
  def self.configure(app, opts=OPTS)
49
- app.opts[:timestamp_public_prefix] = (opts[:prefix] || app.opts[:timestamp_public_prefix] || "static").dup.freeze
49
+ app.opts[:timestamp_public_prefix] = (opts[:prefix] || app.timestamp_public_prefix || "static").dup.freeze
50
+ end
51
+
52
+ module ClassMethods
53
+ RodaPlugins.opt_attr_reader(self, :timestamp_public_prefix)
50
54
  end
51
55
 
52
56
  module InstanceMethods
@@ -54,8 +58,8 @@ class Roda
54
58
  # This does not check the file is inside the directory for performance reasons,
55
59
  # so this should not be called with untrusted input.
56
60
  def timestamp_path(file)
57
- mtime = File.mtime(File.join(opts[:public_root], file))
58
- "/#{opts[:timestamp_public_prefix]}/#{sprintf("%i%06i", mtime.to_i, mtime.usec)}/#{file}"
61
+ mtime = File.mtime(File.join(self.class.public_root, file))
62
+ "/#{self.class.timestamp_public_prefix}/#{sprintf("%i%06i", mtime.to_i, mtime.usec)}/#{file}"
59
63
  end
60
64
  end
61
65
 
@@ -65,7 +69,7 @@ class Roda
65
69
  # a integer segment for the timestamp, and this is a GET request.
66
70
  def timestamp_public
67
71
  if is_get?
68
- on roda_class.opts[:timestamp_public_prefix], Integer do |_|
72
+ on roda_class.timestamp_public_prefix, Integer do |_|
69
73
  public
70
74
  end
71
75
  end
@@ -110,7 +110,7 @@ class Roda
110
110
  }.freeze
111
111
 
112
112
  def self.configure(app, opts = {})
113
- config = (app.opts[:type_routing] || CONFIGURATION).dup
113
+ config = (app.type_routing_opts || CONFIGURATION).dup
114
114
  [:use_extension, :use_header, :default_type].each do |key|
115
115
  config[key] = opts[key] if opts.has_key?(key)
116
116
  end
@@ -149,12 +149,16 @@ class Roda
149
149
  app.opts[:type_routing] = config.freeze
150
150
  end
151
151
 
152
+ module ClassMethods
153
+ RodaPlugins.opt_attr_reader(self, :type_routing, name: :type_routing_opts)
154
+ end
155
+
152
156
  module RequestMethods
153
157
  # Yields if the given +type+ matches the requested data type and halts
154
158
  # the request afterwards, returning the result of the block.
155
159
  def on_type(type, &block)
156
160
  return unless type == requested_type
157
- response[RodaResponseHeaders::CONTENT_TYPE] ||= @scope.opts[:type_routing][:types][type]
161
+ response[RodaResponseHeaders::CONTENT_TYPE] ||= roda_class.type_routing_opts[:types][type]
158
162
  always(&block)
159
163
  end
160
164
 
@@ -162,7 +166,7 @@ class Roda
162
166
  def requested_type
163
167
  return @requested_type if @requested_type
164
168
 
165
- opts = @scope.opts[:type_routing]
169
+ opts = roda_class.type_routing_opts
166
170
  @requested_type = accept_response_type if opts[:use_header]
167
171
  @requested_type ||= opts[:default_type]
168
172
  end
@@ -182,7 +186,7 @@ class Roda
182
186
  # Removes a trailing file extension from the path, and sets
183
187
  # the requested type if so.
184
188
  def _remaining_path(env)
185
- opts = scope.opts[:type_routing]
189
+ opts = roda_class.type_routing_opts
186
190
  path = super
187
191
 
188
192
  if opts[:use_extension]
@@ -197,7 +201,7 @@ class Roda
197
201
 
198
202
  # The response type indicated by the Accept request header.
199
203
  def accept_response_type
200
- mimes = @scope.opts[:type_routing][:mimes]
204
+ mimes = roda_class.type_routing_opts[:mimes]
201
205
  response[RodaResponseHeaders::VARY] = (vary = response[RodaResponseHeaders::VARY]) ? "#{vary}, Accept" : 'Accept'
202
206
 
203
207
  @env['HTTP_ACCEPT'].to_s.split(/\s*,\s*/).map do |part|
@@ -1122,7 +1122,7 @@ class Roda
1122
1122
  # before processing them.
1123
1123
  def self.configure(app, opts=OPTS, &block)
1124
1124
  app.const_set(:TypecastParams, Class.new(RodaPlugins::TypecastParams::Params)) unless app.const_defined?(:TypecastParams)
1125
- app::TypecastParams.class_eval(&block) if block
1125
+ app::TypecastParams.class_eval(&block) if block # RODA4: use class_exec
1126
1126
  if opts[:strip] == :all
1127
1127
  app::TypecastParams.send(:include, StringStripper)
1128
1128
  end
@@ -1133,7 +1133,7 @@ class Roda
1133
1133
  app::TypecastParams.send(:include, SkipBytesizeChecking)
1134
1134
  end
1135
1135
  if opts[:date_parse_input_handler]
1136
- app::TypecastParams.class_eval do
1136
+ app::TypecastParams.class_exec do
1137
1137
  include DateParseInputHandler
1138
1138
  define_method(:handle_date_parse_input, &opts[:date_parse_input_handler])
1139
1139
  private :handle_date_parse_input
@@ -90,7 +90,7 @@ class Roda
90
90
  end
91
91
 
92
92
  if default = opts[:default_size]
93
- app::TypecastParams.class_eval do
93
+ app::TypecastParams.class_exec do
94
94
  meths = ['', 'convert_', '_convert_array_', '_max_input_bytesize_for_', '_invalid_value_message_for_']
95
95
  %w[int uint pos_int pos_uint Integer Integeru].each do |type|
96
96
  meths.each do |prefix|
@@ -1,7 +1,5 @@
1
1
  # frozen-string-literal: true
2
2
 
3
- require 'rack/utils'
4
-
5
3
  #
6
4
  class Roda
7
5
  module RodaPlugins
@@ -24,14 +22,34 @@ class Roda
24
22
  # of the remaining path.
25
23
  def matched_path
26
24
  e = @env
27
- Rack::Utils.unescape(e["SCRIPT_NAME"] + e["PATH_INFO"]).chomp(@remaining_path)
25
+ _unescape_path(e["SCRIPT_NAME"] + e["PATH_INFO"]).chomp(@remaining_path)
28
26
  end
29
27
 
30
28
  private
31
29
 
32
30
  # Unescape the path.
33
31
  def _remaining_path(env)
34
- Rack::Utils.unescape(super)
32
+ _unescape_path(super)
33
+ end
34
+
35
+ if RUBY_VERSION >= "4.0"
36
+ require "cgi/escape"
37
+
38
+ # Use CGI.unescapeURIComponent, which unescapes percent encoding
39
+ # but not +.
40
+ def _unescape_path(path)
41
+ CGI.unescapeURIComponent(path)
42
+ end
43
+ # simplecov:disable
44
+ else
45
+ require 'rack/utils'
46
+
47
+ # Rack::Utils.unescape decodes + as a space, which is only
48
+ # correct for form data, so escape + first to keep it.
49
+ def _unescape_path(path)
50
+ Rack::Utils.unescape(path.gsub('+', '%2B'))
51
+ end
52
+ # simplecov:enable
35
53
  end
36
54
  end
37
55
  end
@@ -16,20 +16,8 @@ class Roda
16
16
  # end
17
17
  module UrlEscape
18
18
  module InstanceMethods
19
- if RUBY_VERSION >= '2'
20
- define_method(:url_escape, Rack::Utils.instance_method(:escape))
21
- define_method(:url_unescape, Rack::Utils.instance_method(:unescape))
22
- # simplecov:disable
23
- else
24
- def url_escape(v)
25
- Rack::Utils.escape(v)
26
- end
27
-
28
- def url_unescape(v)
29
- Rack::Utils.unescape(v)
30
- end
31
- end
32
- # simplecov:enable
19
+ define_method(:url_escape, Rack::Utils.instance_method(:escape))
20
+ define_method(:url_unescape, Rack::Utils.instance_method(:unescape))
33
21
  end
34
22
  end
35
23
 
data/lib/roda/plugins.rb CHANGED
@@ -32,6 +32,40 @@ class Roda
32
32
  plugin
33
33
  end
34
34
 
35
+ # Define an attr_reader method for name that uses the instance variable
36
+ # <tt>@opt_*</tt>. Designed to be used with instance variables set via RodaOpts#[]=.
37
+ def self.opt_attr_reader(mod, key, name: key)
38
+ opt_name = :"opt_#{key}"
39
+ mod.send(:attr_reader, opt_name)
40
+ mod.send(:alias_method, name, opt_name)
41
+ mod.send(:remove_method, opt_name)
42
+ nil
43
+ end
44
+
45
+ # Warn if the opts given contain unsupported keys.
46
+ def self.check_supported_opts(desc, opts, supported_keys)
47
+ extra_keys = opts.keys - supported_keys
48
+
49
+ unless extra_keys.empty?
50
+ warn("Unsupported options given to #{desc}: #{extra_keys.map(&:inspect).join(", ")}", uplevel: 2)
51
+ end
52
+
53
+ nil
54
+ end
55
+
56
+ # Handle positional argument to keyword argument conversion warnings in plugins.
57
+ def self.check_keywords(method, no_positional_opts, opts, kw)
58
+ unless no_positional_opts
59
+ warn("A positional options hash is now deprecated for #{method}. Support for this will be removed in Roda 4. Switch to passing keywords arguments. Keys given in positional options hash: #{opts.keys.map(&:inspect).join(", ")}", uplevel: 2)
60
+ end
61
+
62
+ unless kw.empty?
63
+ warn("Unrecognized keywords given to #{method}: #{kw.keys.join(", ")}. Backwards compatibility for this will be removed in Roda 4.", uplevel: 2)
64
+ end
65
+
66
+ nil
67
+ end
68
+
35
69
  # Register the given plugin with Roda, so that it can be loaded using #plugin
36
70
  # with a symbol. Should be used by plugin files. Example:
37
71
  #
data/lib/roda/request.rb CHANGED
@@ -109,10 +109,10 @@ class Roda
109
109
  # rack response array of status, headers, and body. If no argument
110
110
  # is given, uses the current response.
111
111
  #
112
- # r.halt [200, {'Content-Type'=>'text/html'}, ['Hello World!']]
112
+ # r.halt [200, {'content-type'=>'text/html'}, ['Hello World!']]
113
113
  #
114
114
  # response.status = 200
115
- # response['Content-Type'] = 'text/html'
115
+ # response['content-type'] = 'text/html'
116
116
  # response.write 'Hello World!'
117
117
  # r.halt
118
118
  def halt(res=response.finish)
@@ -328,7 +328,7 @@ class Roda
328
328
  # # matches
329
329
  # end
330
330
  #
331
- # This is usuable inside other match blocks:
331
+ # This is usable inside other match blocks:
332
332
  #
333
333
  # [r.request_method, r.remaining_path]
334
334
  # # => ['GET', '/foo/']
@@ -512,7 +512,7 @@ class Roda
512
512
  end
513
513
  end
514
514
 
515
- # Match the given symbol if any segment matches.
515
+ # Match for any nonempty segment.
516
516
  def _match_symbol(sym=nil)
517
517
  rp = @remaining_path
518
518
  if rp.getbyte(0) == 47
@@ -635,7 +635,7 @@ class Roda
635
635
  # For non-GET requests, redirects to the current path, which will
636
636
  # trigger a GET request. This is to make the common case where
637
637
  # a POST request will redirect to a GET request at the same location
638
- # will work fine.
638
+ # work fine.
639
639
  #
640
640
  # If the current request is a GET request, raise an error, as otherwise
641
641
  # it is easy to create an infinite redirect.
@@ -654,7 +654,7 @@ class Roda
654
654
  302
655
655
  end
656
656
 
657
- # Whether the current path is considered empty.
657
+ # Whether the remaining path is considered empty.
658
658
  def empty_path?
659
659
  @remaining_path.empty?
660
660
  end
@@ -723,13 +723,14 @@ class Roda
723
723
  end
724
724
  end
725
725
 
726
- # How to handle block results that are not nil, false, or a String.
726
+ # Handle block results that are not nil, false, or a String.
727
727
  # By default raises an exception.
728
728
  def unsupported_block_result(result)
729
729
  raise RodaError, "unsupported block result: #{result.inspect}"
730
730
  end
731
731
 
732
732
  # Handle an unsupported matcher.
733
+ # By default raises an exception.
733
734
  def unsupported_matcher(matcher)
734
735
  raise RodaError, "unsupported matcher: #{matcher.inspect}"
735
736
  end
data/lib/roda/response.rb CHANGED
@@ -10,6 +10,7 @@ class Roda
10
10
  # headers used internally by Roda can be lower case on Rack 3, so that it is
11
11
  # possible to use a plain hash of response headers instead of using Rack::Headers.
12
12
  module RodaResponseHeaders
13
+ # RODA4: switch all constant access to downcased strings
13
14
  downcase = defined?(Rack::Headers) && Rack::Headers.is_a?(Class)
14
15
 
15
16
  %w'Allow Cache-Control Content-Disposition Content-Encoding Content-Length
@@ -65,14 +66,14 @@ class Roda
65
66
 
66
67
  # Return the response header with the given key. Example:
67
68
  #
68
- # response['Content-Type'] # => 'text/html'
69
+ # response['content-type'] # => 'text/html'
69
70
  def [](key)
70
71
  @headers[key]
71
72
  end
72
73
 
73
74
  # Set the response header with the given key to the given value.
74
75
  #
75
- # response['Content-Type'] = 'application/json'
76
+ # response['content-type'] = 'application/json'
76
77
  def []=(key, value)
77
78
  @headers[key] = value
78
79
  end
@@ -97,13 +98,13 @@ class Roda
97
98
  # for the current response. If the status has not been set,
98
99
  # uses the return value of default_status if the body has
99
100
  # been written to, otherwise uses a 404 status.
100
- # Adds the Content-Length header to the size of the response body.
101
+ # Adds the content-length header to the size of the response body.
101
102
  #
102
103
  # Example:
103
104
  #
104
105
  # response.finish
105
106
  # # => [200,
106
- # # {'Content-Type'=>'text/html', 'Content-Length'=>'0'},
107
+ # # {'content-type'=>'text/html', 'content-length'=>'0'},
107
108
  # # []]
108
109
  def finish
109
110
  b = @body
@@ -129,7 +130,7 @@ class Roda
129
130
 
130
131
  # Return the rack response array using a given body. Assumes a
131
132
  # 200 response status unless status has been explicitly set,
132
- # and doesn't add the Content-Length header or use the existing
133
+ # and doesn't add the content-length header or use the existing
133
134
  # body.
134
135
  def finish_with_body(body)
135
136
  set_default_headers
@@ -151,8 +152,8 @@ class Roda
151
152
  # Set the Location header to the given path, and the status
152
153
  # to the given status. Example:
153
154
  #
154
- # response.redirect('foo', 301)
155
- # response.redirect('bar')
155
+ # response.redirect('/foo', 301)
156
+ # response.redirect('/bar')
156
157
  def redirect(path, status = 302)
157
158
  @headers[RodaResponseHeaders::LOCATION] = path
158
159
  @status = status
@@ -181,6 +182,7 @@ class Roda
181
182
 
182
183
  # Use Rack::Headers for headers by default on Rack 3
183
184
  def _initialize_headers
185
+ # RODA4: Use {} always, add plugin for using Rack::Headers
184
186
  Rack::Headers.new
185
187
  end
186
188
  else
data/lib/roda/version.rb CHANGED
@@ -4,7 +4,7 @@ class Roda
4
4
  RodaMajorVersion = 3
5
5
 
6
6
  # The minor version of Roda, updated for new feature releases of Roda.
7
- RodaMinorVersion = 108
7
+ RodaMinorVersion = 110
8
8
 
9
9
  # The patch version of Roda, updated only for bug fixes from the last
10
10
  # feature release.