roda 3.55.0 → 3.58.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 (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +34 -0
  3. data/doc/conventions.rdoc +14 -11
  4. data/doc/release_notes/3.56.0.txt +33 -0
  5. data/doc/release_notes/3.57.0.txt +34 -0
  6. data/doc/release_notes/3.58.0.txt +16 -0
  7. data/lib/roda/plugins/chunked.rb +1 -1
  8. data/lib/roda/plugins/common_logger.rb +12 -1
  9. data/lib/roda/plugins/cookies.rb +2 -0
  10. data/lib/roda/plugins/exception_page.rb +20 -4
  11. data/lib/roda/plugins/filter_common_logger.rb +46 -0
  12. data/lib/roda/plugins/hash_branch_view_subdir.rb +76 -0
  13. data/lib/roda/plugins/hash_branches.rb +145 -0
  14. data/lib/roda/plugins/hash_paths.rb +128 -0
  15. data/lib/roda/plugins/hash_routes.rb +13 -176
  16. data/lib/roda/plugins/heartbeat.rb +5 -10
  17. data/lib/roda/plugins/json_parser.rb +6 -2
  18. data/lib/roda/plugins/multi_public.rb +8 -0
  19. data/lib/roda/plugins/multi_route.rb +1 -1
  20. data/lib/roda/plugins/multi_view.rb +0 -4
  21. data/lib/roda/plugins/named_routes.rb +1 -2
  22. data/lib/roda/plugins/not_allowed.rb +13 -0
  23. data/lib/roda/plugins/public.rb +8 -0
  24. data/lib/roda/plugins/route_csrf.rb +1 -0
  25. data/lib/roda/plugins/run_append_slash.rb +1 -1
  26. data/lib/roda/plugins/run_require_slash.rb +46 -0
  27. data/lib/roda/plugins/sessions.rb +1 -0
  28. data/lib/roda/plugins/sinatra_helpers.rb +10 -0
  29. data/lib/roda/plugins/static.rb +2 -0
  30. data/lib/roda/plugins/static_routing.rb +1 -1
  31. data/lib/roda/plugins/status_303.rb +6 -3
  32. data/lib/roda/plugins/status_handler.rb +35 -9
  33. data/lib/roda/plugins/symbol_status.rb +2 -0
  34. data/lib/roda/plugins/unescape_path.rb +2 -0
  35. data/lib/roda/request.rb +35 -1
  36. data/lib/roda/response.rb +5 -0
  37. data/lib/roda/version.rb +1 -1
  38. metadata +30 -5
@@ -15,24 +15,53 @@ class Roda
15
15
  # status_handler(403) do
16
16
  # "You are forbidden from seeing that!"
17
17
  # end
18
+ #
18
19
  # status_handler(404) do
19
20
  # "Where did it go?"
20
21
  # end
21
22
  #
23
+ # status_handler(405, keep_headers: ['Accept']) do
24
+ # "Use a different method!"
25
+ # end
26
+ #
22
27
  # Before a block is called, any existing headers on the response will be
23
- # cleared. So if you want to be sure the headers are set even in your block,
24
- # you need to reset them in the block.
28
+ # cleared, unless the +:keep_headers+ option is used. If the +:keep_headers+
29
+ # option is used, the value should be an array, and only the headers listed
30
+ # in the array will be kept.
25
31
  module StatusHandler
32
+ CLEAR_HEADERS = :clear.to_proc
33
+ private_constant :CLEAR_HEADERS
34
+
26
35
  def self.configure(app)
27
36
  app.opts[:status_handler] ||= {}
28
37
  end
29
38
 
30
39
  module ClassMethods
31
40
  # Install the given block as a status handler for the given HTTP response code.
32
- def status_handler(code, &block)
41
+ def status_handler(code, opts=OPTS, &block)
33
42
  # For backwards compatibility, pass request argument if block accepts argument
34
43
  arity = block.arity == 0 ? 0 : 1
35
- opts[:status_handler][code] = [define_roda_method(:"_roda_status_handler_#{code}", arity, &block), arity]
44
+ handle_headers = case keep_headers = opts[:keep_headers]
45
+ when nil, false
46
+ CLEAR_HEADERS
47
+ when Array
48
+ # :nocov:
49
+ if Rack.release >= '2.3'
50
+ keep_headers = keep_headers.map(&:downcase)
51
+ end
52
+ # :nocov:
53
+ lambda{|headers| headers.delete_if{|k,_| !keep_headers.include?(k)}}
54
+ else
55
+ raise RodaError, "Invalid :keep_headers option"
56
+ end
57
+
58
+ meth = define_roda_method(:"_roda_status_handler__#{code}", arity, &block)
59
+ self.opts[:status_handler][code] = define_roda_method(:"_roda_status_handler_#{code}", 1) do |result|
60
+ res = @_response
61
+ res.status = result[0]
62
+ handle_headers.call(res.headers)
63
+ result.replace(_roda_handle_route{arity == 1 ? send(meth, @_request) : send(meth)})
64
+ end
36
65
  end
37
66
 
38
67
  # Freeze the hash of status handlers so that there can be no thread safety issues at runtime.
@@ -47,11 +76,8 @@ class Roda
47
76
 
48
77
  # If routing returns a response we have a handler for, call that handler.
49
78
  def _roda_after_20__status_handler(result)
50
- if result && (meth, arity = opts[:status_handler][result[0]]; meth) && (v = result[2]).is_a?(Array) && v.empty?
51
- res = @_response
52
- res.headers.clear
53
- res.status = result[0]
54
- result.replace(_roda_handle_route{arity == 1 ? send(meth, @_request) : send(meth)})
79
+ if result && (meth = opts[:status_handler][result[0]]) && (v = result[2]).is_a?(Array) && v.empty?
80
+ send(meth, result)
55
81
  end
56
82
  end
57
83
  end
@@ -1,5 +1,7 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ require 'rack/utils'
4
+
3
5
  class Roda
4
6
  module RodaPlugins
5
7
  # The symbol_status plugin patches the +status=+ response method to
@@ -1,5 +1,7 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ require 'rack/utils'
4
+
3
5
  #
4
6
  class Roda
5
7
  module RodaPlugins
data/lib/roda/request.rb CHANGED
@@ -1,6 +1,19 @@
1
1
  # frozen-string-literal: true
2
2
 
3
- require "rack"
3
+ # :nocov:
4
+ begin
5
+ require "rack/version"
6
+ rescue LoadError
7
+ require "rack"
8
+ else
9
+ if Rack.release >= '2.3'
10
+ require "rack/request"
11
+ else
12
+ require "rack"
13
+ end
14
+ end
15
+ # :nocov:
16
+
4
17
  require_relative "cache"
5
18
 
6
19
  class Roda
@@ -116,6 +129,27 @@ class Roda
116
129
  "#<#{self.class.inspect} #{@env["REQUEST_METHOD"]} #{path}>"
117
130
  end
118
131
 
132
+ # :nocov:
133
+ if Rack.release >= '2.3'
134
+ def http_version
135
+ # Prefer SERVER_PROTOCOL as it is required in Rack 3.
136
+ # Still fall back to HTTP_VERSION if SERVER_PROTOCOL
137
+ # is not set, in case the server in use is not Rack 3
138
+ # compliant.
139
+ @env['SERVER_PROTOCOL'] || @env['HTTP_VERSION']
140
+ end
141
+ else
142
+ # :nocov:
143
+ # What HTTP version the request was submitted with.
144
+ def http_version
145
+ # Prefer HTTP_VERSION as it is backwards compatible
146
+ # with previous Roda versions. Fallback to
147
+ # SERVER_PROTOCOL for servers that do not set
148
+ # HTTP_VERSION.
149
+ @env['HTTP_VERSION'] || @env['SERVER_PROTOCOL']
150
+ end
151
+ end
152
+
119
153
  # Does a terminal match on the current path, matching only if the arguments
120
154
  # have fully matched the path. If it matches, the match block is
121
155
  # executed, and when the match block returns, the rack response is
data/lib/roda/response.rb CHANGED
@@ -1,5 +1,10 @@
1
1
  # frozen-string-literal: true
2
2
 
3
+ begin
4
+ require 'rack/headers'
5
+ rescue LoadError
6
+ end
7
+
3
8
  class Roda
4
9
  # Base class used for Roda responses. The instance methods for this
5
10
  # class are added by Roda::RodaPlugins::Base::ResponseMethods, the class
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 = 55
7
+ RodaMinorVersion = 58
8
8
 
9
9
  # The patch version of Roda, updated only for bug fixes from the last
10
10
  # feature release.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.55.0
4
+ version: 3.58.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-12 00:00:00.000000000 Z
11
+ date: 2022-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 5.7.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-hooks
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: minitest-global_expectations
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -213,6 +227,9 @@ extra_rdoc_files:
213
227
  - doc/release_notes/3.53.0.txt
214
228
  - doc/release_notes/3.54.0.txt
215
229
  - doc/release_notes/3.55.0.txt
230
+ - doc/release_notes/3.56.0.txt
231
+ - doc/release_notes/3.57.0.txt
232
+ - doc/release_notes/3.58.0.txt
216
233
  - doc/release_notes/3.6.0.txt
217
234
  - doc/release_notes/3.7.0.txt
218
235
  - doc/release_notes/3.8.0.txt
@@ -275,6 +292,9 @@ files:
275
292
  - doc/release_notes/3.53.0.txt
276
293
  - doc/release_notes/3.54.0.txt
277
294
  - doc/release_notes/3.55.0.txt
295
+ - doc/release_notes/3.56.0.txt
296
+ - doc/release_notes/3.57.0.txt
297
+ - doc/release_notes/3.58.0.txt
278
298
  - doc/release_notes/3.6.0.txt
279
299
  - doc/release_notes/3.7.0.txt
280
300
  - doc/release_notes/3.8.0.txt
@@ -318,10 +338,14 @@ files:
318
338
  - lib/roda/plugins/error_handler.rb
319
339
  - lib/roda/plugins/error_mail.rb
320
340
  - lib/roda/plugins/exception_page.rb
341
+ - lib/roda/plugins/filter_common_logger.rb
321
342
  - lib/roda/plugins/flash.rb
322
343
  - lib/roda/plugins/h.rb
323
344
  - lib/roda/plugins/halt.rb
345
+ - lib/roda/plugins/hash_branch_view_subdir.rb
346
+ - lib/roda/plugins/hash_branches.rb
324
347
  - lib/roda/plugins/hash_matcher.rb
348
+ - lib/roda/plugins/hash_paths.rb
325
349
  - lib/roda/plugins/hash_routes.rb
326
350
  - lib/roda/plugins/head.rb
327
351
  - lib/roda/plugins/header_matchers.rb
@@ -374,6 +398,7 @@ files:
374
398
  - lib/roda/plugins/route_csrf.rb
375
399
  - lib/roda/plugins/run_append_slash.rb
376
400
  - lib/roda/plugins/run_handler.rb
401
+ - lib/roda/plugins/run_require_slash.rb
377
402
  - lib/roda/plugins/sessions.rb
378
403
  - lib/roda/plugins/shared_vars.rb
379
404
  - lib/roda/plugins/sinatra_helpers.rb
@@ -396,13 +421,13 @@ files:
396
421
  - lib/roda/response.rb
397
422
  - lib/roda/session_middleware.rb
398
423
  - lib/roda/version.rb
399
- homepage: http://roda.jeremyevans.net
424
+ homepage: https://roda.jeremyevans.net
400
425
  licenses:
401
426
  - MIT
402
427
  metadata:
403
428
  bug_tracker_uri: https://github.com/jeremyevans/roda/issues
404
- changelog_uri: http://roda.jeremyevans.net/rdoc/files/CHANGELOG.html
405
- documentation_uri: http://roda.jeremyevans.net/documentation.html
429
+ changelog_uri: https://roda.jeremyevans.net/rdoc/files/CHANGELOG.html
430
+ documentation_uri: https://roda.jeremyevans.net/documentation.html
406
431
  mailing_list_uri: https://github.com/jeremyevans/roda/discussions
407
432
  source_code_uri: https://github.com/jeremyevans/roda
408
433
  post_install_message: