Class: Bullet::Rack
Constant Summary
collapse
- NONCE_MATCHER =
/script-src .*'nonce-(?<nonce>[A-Za-z0-9+\/]+={0,2})'/
Instance Method Summary
collapse
Methods included from Dependency
#active_record40?, #active_record41?, #active_record42?, #active_record4?, #active_record50?, #active_record51?, #active_record52?, #active_record5?, #active_record60?, #active_record61?, #active_record6?, #active_record70?, #active_record71?, #active_record72?, #active_record7?, #active_record80?, #active_record8?, #active_record?, #active_record_version, #mongoid4x?, #mongoid5x?, #mongoid6x?, #mongoid7x?, #mongoid8x?, #mongoid?, #mongoid_version
Constructor Details
#initialize(app) ⇒ Rack
Returns a new instance of Rack.
9
10
11
|
# File 'lib/bullet/rack.rb', line 9
def initialize(app)
@app = app
end
|
Instance Method Details
#append_to_html_body(response_body, content) ⇒ Object
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/bullet/rack.rb', line 57
def append_to_html_body(response_body, content)
body = response_body.dup
content = content.html_safe if content.respond_to?(:html_safe)
if body.include?('</body>')
position = body.rindex('</body>')
body.insert(position, content)
else
body << content
end
end
|
#call(env) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/bullet/rack.rb', line 13
def call(env)
return @app.call(env) unless Bullet.enable?
Bullet.start_request
status, , response = @app.call(env)
response_body = nil
if Bullet.notification? || Bullet.always_append_html_body
if Bullet.inject_into_page? && !file?() && !sse?() && !empty?(response) && status == 200
if html_request?(, response)
response_body = response_body(response)
with_security_policy_nonce() do |nonce|
response_body = append_to_html_body(response_body, ) if Bullet.
response_body = append_to_html_body(response_body, Bullet.gather_inline_notifications)
if Bullet. && !Bullet.
response_body = append_to_html_body(response_body, xhr_script(nonce))
end
end
['Content-Length'] = response_body.bytesize.to_s
elsif !Bullet.
(, 'X-bullet-footer-text', Bullet..uniq) if Bullet.
(, 'X-bullet-console-text', Bullet.text_notifications) if Bullet.console_enabled?
end
end
Bullet.perform_out_of_channel_notifications(env)
end
[status, , response_body ? [response_body] : response]
ensure
Bullet.end_request
end
|
#empty?(response) ⇒ Boolean
fix issue if response’s body is a Proc
48
49
50
51
52
53
54
55
|
# File 'lib/bullet/rack.rb', line 48
def empty?(response)
return true if !response.respond_to?(:body) && !response.respond_to?(:first)
body = response_body(response)
body.nil? || body.empty?
end
|
#file?(headers) ⇒ Boolean
80
81
82
|
# File 'lib/bullet/rack.rb', line 80
def file?()
['Content-Transfer-Encoding'] == 'binary' || ['Content-Disposition']
end
|
68
69
70
|
# File 'lib/bullet/rack.rb', line 68
def
"<details #{details_attributes}><summary #{summary_attributes}>Bullet Warnings</summary><div #{}>#{Bullet..uniq.join('<br>')}#{}</div></details>"
end
|
#html_request?(headers, response) ⇒ Boolean
88
89
90
|
# File 'lib/bullet/rack.rb', line 88
def html_request?(, response)
['Content-Type']&.include?('text/html')
end
|
#response_body(response) ⇒ Object
92
93
94
95
96
97
98
|
# File 'lib/bullet/rack.rb', line 92
def response_body(response)
if response.respond_to?(:body)
Array === response.body ? response.body.first : response.body
elsif response.respond_to?(:first)
response.first
end
end
|
72
73
74
75
76
77
78
|
# File 'lib/bullet/rack.rb', line 72
def (, , )
.pop while .to_json.length > 8 * 1024
[] = .to_json
end
|
#sse?(headers) ⇒ Boolean
84
85
86
|
# File 'lib/bullet/rack.rb', line 84
def sse?()
['Content-Type'] == 'text/event-stream'
end
|