rails-hush 1.1.0 → 1.1.1
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/README.md +3 -3
- data/lib/rails_hush/middleware/hush_one.rb +2 -1
- data/lib/rails_hush/middleware/hush_two.rb +2 -1
- data/lib/rails_hush/middleware/show_exceptions.rb +24 -0
- data/lib/rails_hush/middleware/simple_renderer.rb +33 -31
- data/lib/rails_hush/version.rb +1 -1
- data/lib/rails_hush.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a9c38ec9eb1c74c7be0f5be8400851ff7b4e18d09cf13f45d78dc0a661e91a5
|
4
|
+
data.tar.gz: fdefce31691aab5c96c685ee6a4688545d11d9fd66a926ac15845d593df23033
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8beddfa617f90cb92c7860bc1b23498738d5f722f2467c2c80f81c43e57464184abe6df3a00f0889edcd1a210df3b55a70bfe58c6ed968eefe7f8439923d8612
|
7
|
+
data.tar.gz: 527686f8e8edc9accdeff52175fc737752bea3ef7b44ef8932f8a530c1a0bc6e71da8f2cb3bf543552a342f0a457968149ece42b714cf7588d3ccb44b807f881
|
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 =
|
45
|
+
config.rails_hush.use_one = false
|
46
46
|
# Phase two (late) middleware
|
47
|
-
config.rails_hush.use_two =
|
47
|
+
config.rails_hush.use_two = false
|
48
48
|
|
49
49
|
Then add the middleware on your own:
|
50
50
|
|
@@ -78,7 +78,7 @@ Rails' default "test" environment settings are quite different than "production"
|
|
78
78
|
|
79
79
|
## Contributing
|
80
80
|
|
81
|
-
Contributions welcome. Please use standard
|
81
|
+
Contributions welcome. Please use standard GitHub Pull Requests.
|
82
82
|
|
83
83
|
|
84
84
|
## 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
|
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,7 +10,7 @@ module RailsHush
|
|
9
10
|
|
10
11
|
def call(env)
|
11
12
|
request = ActionDispatch::Request.new env
|
12
|
-
if
|
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
16
|
if headers['X-Cascade'] == 'pass'
|
@@ -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
|
1
|
+
module RailsHush
|
2
|
+
module SimpleRenderer
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
data/lib/rails_hush/version.rb
CHANGED
data/lib/rails_hush.rb
CHANGED
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.
|
4
|
+
version: 1.1.1
|
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-
|
11
|
+
date: 2023-05-27 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.
|
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.
|
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
|