rails-hush 1.1.0 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28eb5448f9a28b437d7cb46cbba086fc16c891df1a8083a694ed12fba56bcd32
4
- data.tar.gz: c4b6f533e00e33e1b85c08abffe2fa863bdadbbe55e6709fefd522160e40fc0c
3
+ metadata.gz: e226558e55919c5d99da20ebda38c44d225e07a0fad281d8552184cce9f245cc
4
+ data.tar.gz: 4b6b7d90fda79f966493afb91b147ab4f543b8e5a4ff0c668a32dc8b5e4998f7
5
5
  SHA512:
6
- metadata.gz: c2cca48d9b7558a79a5421f709c25277a670abcf19f46ab2b5c0a6ecc4bd7ce49e08276eeb381b5bc7ed34fe56c41b0354652edb1fa11a2569f0bf46697c249c
7
- data.tar.gz: b900f8c397cf312c16347746333311dcd0f8ad2e22daf935c6d953cd4c0e400cb34e0eebbbdedd3172fbf3d06016113d5bbd43965f6c009c45e22bf7fe68b80c
6
+ metadata.gz: 4632f350f3ac1f71f0f4db2e8974d2f686f923b10e2933644703b39683d67b5737f1169768e4ea6772e8f8ea94082b0bd48c7e695392ba7e9b38076fe7e71545
7
+ data.tar.gz: 88722e2d0c8528607b601992600e00964a5d5f62cec3101404667663f1254352c7e4c522800f61bbe43f6076275f6690ffe57a66356287ef20a466678f282685
data/README.md CHANGED
@@ -42,9 +42,9 @@ RailsHush does support a couple of configuration options:
42
42
  To disable automatic loading of middleware:
43
43
 
44
44
  # Phase one (early) middleware
45
- config.rails_hush.use_one = true
45
+ config.rails_hush.use_one = false
46
46
  # Phase two (late) middleware
47
- config.rails_hush.use_two = true
47
+ config.rails_hush.use_two = false
48
48
 
49
49
  Then add the middleware on your own:
50
50
 
@@ -73,12 +73,13 @@ RailsHush also has a replaceable renderer, in case you don't like the default js
73
73
  Rails' default "test" environment settings are quite different than "production". While the default settings are quite appropriate, with them it is near impossible to test the actual behavior of RailsHush, because it will effectively be disabled in "test". On the whole, it's recommended to just rely on RailsHush's own test suite. However, if you really want to test its behavior inside your app, change the following in `environments/test.rb`:
74
74
 
75
75
  config.consider_all_requests_local = false
76
- config.action_dispatch.show_exceptions = true
76
+ config.action_dispatch.show_exceptions = true # rails <= 7.0
77
+ config.action_dispatch.show_exceptions = :rescuable # rails >= 7.1
77
78
 
78
79
 
79
80
  ## Contributing
80
81
 
81
- Contributions welcome. Please use standard Github Pull Requests.
82
+ Contributions welcome. Please use standard GitHub Pull Requests.
82
83
 
83
84
 
84
85
  ## License
@@ -1,5 +1,6 @@
1
1
  module RailsHush
2
2
  class HushOne
3
+ include ShowExceptions
3
4
  include SimpleRenderer
4
5
 
5
6
  def initialize(app, renderer=nil)
@@ -9,7 +10,7 @@ module RailsHush
9
10
 
10
11
  def call(env)
11
12
  request = ActionDispatch::Request.new env
12
- if request.show_exceptions? && !request.get_header("action_dispatch.show_detailed_exceptions")
13
+ if show_exceptions?(request) && !request.get_header("action_dispatch.show_detailed_exceptions")
13
14
  begin
14
15
  @app.call(env)
15
16
  rescue ActionController::UnknownHttpMethod
@@ -1,5 +1,6 @@
1
1
  module RailsHush
2
2
  class HushTwo
3
+ include ShowExceptions
3
4
  include SimpleRenderer
4
5
 
5
6
  def initialize(app, renderer=nil)
@@ -9,10 +10,10 @@ module RailsHush
9
10
 
10
11
  def call(env)
11
12
  request = ActionDispatch::Request.new env
12
- if request.show_exceptions? && !request.get_header("action_dispatch.show_detailed_exceptions")
13
+ if show_exceptions?(request) && !request.get_header("action_dispatch.show_detailed_exceptions")
13
14
  begin
14
15
  _, headers, body = response = @app.call(env)
15
- if headers['X-Cascade'] == 'pass'
16
+ if headers['X-Cascade'] == 'pass' || headers['x-cascade'] == 'pass'
16
17
  body.close if body.respond_to?(:close)
17
18
  raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"
18
19
  end
@@ -0,0 +1,24 @@
1
+ module RailsHush
2
+ module ShowExceptions
3
+
4
+ # actionpack treats missing/invalid values as :all/true. since railties (eg: a full rails
5
+ # app) defaults to :all, skipping the invalid value case here to improve code clarity.
6
+ # since rails-hush intentionally overrides certain exceptions, treat :rescuable the same
7
+ # as :all. there's no need to be dynamic here.
8
+ SHOWABLE = [
9
+ :all, # rails 7.1+
10
+ true, # rails 7.0-
11
+ nil, # equiv to :all,true
12
+ :rescuable # rails 7.1+
13
+ ]
14
+
15
+ def show_exceptions?(request, exception=nil)
16
+ if Rails.version >= '7.1'
17
+ SHOWABLE.include? request.get_header("action_dispatch.show_exceptions")
18
+ else
19
+ request.show_exceptions?
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -1,38 +1,40 @@
1
- module SimpleRenderer
1
+ module RailsHush
2
+ module SimpleRenderer
2
3
 
3
- def log_request(status, request)
4
- payload = {
5
- params: (request.filtered_parameters rescue {}),
6
- headers: request.headers,
7
- format: (request.format.ref rescue :text),
8
- method: (request.request_method rescue 'INVALID'),
9
- path: request.fullpath,
10
- status: status
11
- }
12
- ActiveSupport::Notifications.instrument "process_action.action_controller", payload
13
- end
4
+ def log_request(status, request)
5
+ payload = {
6
+ params: (request.filtered_parameters rescue {}),
7
+ headers: request.headers,
8
+ format: (request.format.ref rescue :text),
9
+ method: (request.request_method rescue 'INVALID'),
10
+ path: request.fullpath,
11
+ status: status
12
+ }
13
+ ActiveSupport::Notifications.instrument "process_action.action_controller", payload
14
+ end
14
15
 
15
- def render(status, request, error=nil)
16
- begin
17
- content_type = request.formats.first
18
- rescue Mime::Type::InvalidMimeType
19
- content_type = Mime[:text]
16
+ def render(status, request, error=nil)
17
+ begin
18
+ content_type = request.formats.first
19
+ rescue Mime::Type::InvalidMimeType
20
+ content_type = Mime[:text]
21
+ end
22
+ error ||= Rack::Utils::HTTP_STATUS_CODES.fetch(status, Rack::Utils::HTTP_STATUS_CODES[500])
23
+ @renderer.call(status, content_type, error)
20
24
  end
21
- error ||= Rack::Utils::HTTP_STATUS_CODES.fetch(status, Rack::Utils::HTTP_STATUS_CODES[500])
22
- @renderer.call(status, content_type, error)
23
- end
24
25
 
25
- def default_renderer(status, content_type, error)
26
- body = { status: status, error: error }
27
- format = "to_#{content_type.to_sym}" if content_type
28
- if format && body.respond_to?(format)
29
- body = body.public_send(format)
30
- else
31
- content_type = 'application/json'
32
- body = body.to_json
26
+ def default_renderer(status, content_type, error)
27
+ body = { status: status, error: error }
28
+ format = "to_#{content_type.to_sym}" if content_type
29
+ if format && body.respond_to?(format)
30
+ body = body.public_send(format)
31
+ else
32
+ content_type = 'application/json'
33
+ body = body.to_json
34
+ end
35
+ [status, { "Content-Type" => "#{content_type}; charset=#{ActionDispatch::Response.default_charset}",
36
+ "Content-Length" => body.bytesize.to_s }, [body]]
33
37
  end
34
- [status, { "Content-Type" => "#{content_type}; charset=#{ActionDispatch::Response.default_charset}",
35
- "Content-Length" => body.bytesize.to_s }, [body]]
36
- end
37
38
 
39
+ end
38
40
  end
@@ -1,3 +1,3 @@
1
1
  module RailsHush
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.2'
3
3
  end
data/lib/rails_hush.rb CHANGED
@@ -1,4 +1,4 @@
1
- %w(simple_renderer hush_one hush_two).each do |f|
1
+ %w(show_exceptions simple_renderer hush_one hush_two).each do |f|
2
2
  require "rails_hush/middleware/#{f}"
3
3
  end
4
4
  require 'rails_hush/railtie'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-hush
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - thomas morgan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-10 00:00:00.000000000 Z
11
+ date: 2023-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '6'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7.1'
22
+ version: '7.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '6'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '7.1'
32
+ version: '7.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: sqlite3
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -73,6 +73,7 @@ files:
73
73
  - lib/rails_hush.rb
74
74
  - lib/rails_hush/middleware/hush_one.rb
75
75
  - lib/rails_hush/middleware/hush_two.rb
76
+ - lib/rails_hush/middleware/show_exceptions.rb
76
77
  - lib/rails_hush/middleware/simple_renderer.rb
77
78
  - lib/rails_hush/railtie.rb
78
79
  - lib/rails_hush/version.rb