copy_tuner_client 0.1.1.beta16 → 0.1.1.beta17
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +2 -2
- data/lib/copy_tuner_client/copyray_middleware.rb +19 -27
- data/lib/copy_tuner_client/version.rb +1 -1
- metadata +3 -3
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
copy_tuner_client (0.1.1.
|
4
|
+
copy_tuner_client (0.1.1.beta17)
|
5
5
|
i18n (>= 0.5.0)
|
6
6
|
json
|
7
7
|
|
@@ -70,7 +70,7 @@ GEM
|
|
70
70
|
multi_json (~> 1.3)
|
71
71
|
hike (1.2.1)
|
72
72
|
i18n (0.6.0)
|
73
|
-
json (1.8.
|
73
|
+
json (1.8.2)
|
74
74
|
mail (2.3.0)
|
75
75
|
i18n (>= 0.4.0)
|
76
76
|
mime-types (~> 1.16)
|
@@ -8,12 +8,21 @@ module CopyTunerClient
|
|
8
8
|
|
9
9
|
def call(env)
|
10
10
|
status, headers, response = @app.call(env)
|
11
|
-
if
|
12
|
-
body = append_css!(
|
11
|
+
if html_headers?(status, headers) && body = response_body(response)
|
12
|
+
body = append_css!(body)
|
13
13
|
body = append_js!(body)
|
14
|
-
|
14
|
+
content_length = body.bytesize.to_s
|
15
|
+
if ActionDispatch::Response === response
|
16
|
+
response.body = [body]
|
17
|
+
response.headers['Content-Length'] = content_length
|
18
|
+
response.to_a
|
19
|
+
else
|
20
|
+
headers['Content-Length'] = content_length
|
21
|
+
[status, headers, [body]]
|
22
|
+
end
|
23
|
+
else
|
24
|
+
[status, headers, response]
|
15
25
|
end
|
16
|
-
[status, headers, (body ? [body] : response)]
|
17
26
|
end
|
18
27
|
|
19
28
|
private
|
@@ -22,8 +31,8 @@ module CopyTunerClient
|
|
22
31
|
ActionController::Base.helpers
|
23
32
|
end
|
24
33
|
|
25
|
-
def append_css!(
|
26
|
-
|
34
|
+
def append_css!(html)
|
35
|
+
html.sub(/<body[^>]*>/) { "#{$~}\n#{css_tag}" }
|
27
36
|
end
|
28
37
|
|
29
38
|
def append_js!(html)
|
@@ -47,37 +56,20 @@ module CopyTunerClient
|
|
47
56
|
helpers.stylesheet_link_tag :copyray
|
48
57
|
end
|
49
58
|
|
50
|
-
def should_inject_xray?(status, headers, response)
|
51
|
-
status == 200 &&
|
52
|
-
html_request?(headers, response) &&
|
53
|
-
!empty?(response) &&
|
54
|
-
!file?(headers) &&
|
55
|
-
!response.body.frozen?
|
56
|
-
end
|
57
|
-
|
58
|
-
def empty?(response)
|
59
|
-
# response may be ["Not Found"], ["Move Permanently"], etc.
|
60
|
-
(response.is_a?(Array) && response.size <= 1) ||
|
61
|
-
!response.respond_to?(:body) || response.body.empty?
|
62
|
-
end
|
63
|
-
|
64
59
|
def file?(headers)
|
65
60
|
headers["Content-Transfer-Encoding"] == "binary"
|
66
61
|
end
|
67
62
|
|
68
|
-
def
|
63
|
+
def html_headers?(status, headers)
|
64
|
+
status == 200 &&
|
69
65
|
headers['Content-Type'] &&
|
70
66
|
headers['Content-Type'].include?('text/html') &&
|
71
|
-
|
67
|
+
!file?(headers)
|
72
68
|
end
|
73
69
|
|
74
70
|
def response_body(response)
|
75
71
|
body = ''
|
76
|
-
|
77
|
-
response.each { |s| body << s }
|
78
|
-
else
|
79
|
-
body = response
|
80
|
-
end
|
72
|
+
response.each { |s| body << s.to_s }
|
81
73
|
body
|
82
74
|
end
|
83
75
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: copy_tuner_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.1.
|
4
|
+
version: 0.1.1.beta17
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-02-
|
12
|
+
date: 2015-02-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: i18n
|
@@ -349,7 +349,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
349
349
|
version: '0'
|
350
350
|
segments:
|
351
351
|
- 0
|
352
|
-
hash: -
|
352
|
+
hash: -4147796897350930747
|
353
353
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
354
354
|
none: false
|
355
355
|
requirements:
|