xray-rails 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -32,15 +32,15 @@ module Xray
32
32
  res.status = 400
33
33
  end
34
34
  res.finish
35
- # Inject xray.js and friends if it's a plain ol' successful HTML request.
35
+ # Inject xray.js and friends if this is a successful HTML response
36
36
  else
37
37
  status, headers, response = @app.call(env)
38
- if should_inject_xray?(status, headers, response)
39
- body = response.body.sub(/<body[^>]*>/) { "#{$~}\n#{xray_bar}" }
38
+ if html_headers?(status, headers) && body = response_body(response)
39
+ body = body.sub(/<body[^>]*>/) { "#{$~}\n#{xray_bar}" }
40
40
  # Inject js script tags if assets are unbundled
41
41
  if Rails.application.config.assets.debug
42
- append_js!(body, 'jquery', :xray)
43
- append_js!(body, 'backbone', :'xray-backbone')
42
+ append_js!(body, 'jquery', 'xray')
43
+ append_js!(body, 'backbone', 'xray-backbone')
44
44
  end
45
45
  headers['Content-Length'] = body.bytesize.to_s
46
46
  end
@@ -66,26 +66,17 @@ module Xray
66
66
  end
67
67
  end
68
68
 
69
- def should_inject_xray?(status, headers, response)
69
+ def html_headers?(status, headers)
70
70
  status == 200 &&
71
- html_request?(headers, response) &&
72
- !empty?(response) &&
73
- !file?(headers) &&
74
- !response.body.frozen?
71
+ headers['Content-Type'] &&
72
+ headers['Content-Type'].include?('text/html') &&
73
+ headers["Content-Transfer-Encoding"] != "binary"
75
74
  end
76
75
 
77
- def empty?(response)
78
- # response may be ["Not Found"], ["Move Permanently"], etc.
79
- (response.is_a?(Array) && response.size <= 1) ||
80
- !response.respond_to?(:body) || response.body.empty?
81
- end
82
-
83
- def file?(headers)
84
- headers["Content-Transfer-Encoding"] == "binary"
85
- end
86
-
87
- def html_request?(headers, response)
88
- headers['Content-Type'] && headers['Content-Type'].include?('text/html') && response.body.include?("<html")
76
+ def response_body(response)
77
+ body = ''
78
+ response.each { |s| body << s.to_s }
79
+ body
89
80
  end
90
81
  end
91
82
  end
data/lib/xray/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Xray
2
- VERSION = "0.1.9"
2
+ VERSION = "0.1.10"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xray-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  prerelease:
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: 2013-11-15 00:00:00.000000000 Z
12
+ date: 2013-12-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -203,12 +203,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
203
203
  - - ! '>='
204
204
  - !ruby/object:Gem::Version
205
205
  version: '0'
206
+ segments:
207
+ - 0
208
+ hash: -221572238928851522
206
209
  required_rubygems_version: !ruby/object:Gem::Requirement
207
210
  none: false
208
211
  requirements:
209
212
  - - ! '>='
210
213
  - !ruby/object:Gem::Version
211
214
  version: '0'
215
+ segments:
216
+ - 0
217
+ hash: -221572238928851522
212
218
  requirements: []
213
219
  rubyforge_project:
214
220
  rubygems_version: 1.8.23