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 +4 -4
- data/README.md +5 -4
- data/lib/rails_hush/middleware/hush_one.rb +2 -1
- data/lib/rails_hush/middleware/hush_two.rb +3 -2
- 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: e226558e55919c5d99da20ebda38c44d225e07a0fad281d8552184cce9f245cc
|
4
|
+
data.tar.gz: 4b6b7d90fda79f966493afb91b147ab4f543b8e5a4ff0c668a32dc8b5e4998f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 =
|
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
|
|
@@ -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
|
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
|
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
|
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
|
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.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
|
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.
|
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
|