rack-stripper 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rack/stripper.rb +15 -9
- data/rack-stripper.gemspec +2 -1
- metadata +24 -8
data/lib/rack/stripper.rb
CHANGED
@@ -2,14 +2,14 @@ require 'rack'
|
|
2
2
|
|
3
3
|
module Rack
|
4
4
|
class Stripper
|
5
|
-
VERSION = '1.0
|
5
|
+
VERSION = '1.1.0'
|
6
6
|
|
7
7
|
attr_accessor :add_xml_instruction
|
8
8
|
attr_accessor :is_xml_response
|
9
9
|
|
10
10
|
def initialize(app, options={})
|
11
11
|
@app = app
|
12
|
-
|
12
|
+
@add_xml_instruction = options[:add_xml_instruction] || false
|
13
13
|
end
|
14
14
|
|
15
15
|
def call(env)
|
@@ -19,16 +19,22 @@ module Rack
|
|
19
19
|
def _call(env)
|
20
20
|
status, headers, response = @app.call(env)
|
21
21
|
|
22
|
+
if status != 200
|
23
|
+
return [status, headers, response]
|
24
|
+
end
|
25
|
+
|
22
26
|
if headers.has_key?('Content-Type')
|
23
27
|
self.is_xml_response = !headers['Content-Type'].match(/xml/).nil?
|
24
28
|
end
|
25
29
|
|
26
30
|
if response.respond_to?(:body)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
+
response.body = process_body(response.body)
|
32
|
+
if headers.has_key?('Content-Length')
|
33
|
+
headers['Content-Length'] = response.body.bytesize
|
34
|
+
end
|
31
35
|
end
|
36
|
+
|
37
|
+
[status, headers, response]
|
32
38
|
end
|
33
39
|
|
34
40
|
protected
|
@@ -36,7 +42,7 @@ module Rack
|
|
36
42
|
def process_body(body)
|
37
43
|
body = body[0] if body.is_a?(Array)
|
38
44
|
body.strip!
|
39
|
-
if
|
45
|
+
if @add_xml_instruction && @is_xml_response && lacks_instruction?(body)
|
40
46
|
body = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n#{body}"
|
41
47
|
end
|
42
48
|
body
|
@@ -48,8 +54,8 @@ module Rack
|
|
48
54
|
# @param [String] body The body of the text.
|
49
55
|
#
|
50
56
|
# @return [Boolean] true if the content doesn't have an XML instruction, false if it does.
|
51
|
-
def
|
57
|
+
def lacks_instruction?(body)
|
52
58
|
body.index('<?xml ').nil? rescue false
|
53
59
|
end
|
54
60
|
end
|
55
|
-
end
|
61
|
+
end
|
data/rack-stripper.gemspec
CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.version = Rack::Stripper::VERSION
|
17
17
|
|
18
18
|
gem.add_development_dependency 'rspec'
|
19
|
+
gem.add_development_dependency 'rake'
|
19
20
|
gem.add_development_dependency 'debugger'
|
20
|
-
gem.
|
21
|
+
gem.add_runtime_dependency 'rack', '~> 1.4.5'
|
21
22
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-stripper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
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:
|
12
|
+
date: 2013-03-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: debugger
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -48,17 +64,17 @@ dependencies:
|
|
48
64
|
requirement: !ruby/object:Gem::Requirement
|
49
65
|
none: false
|
50
66
|
requirements:
|
51
|
-
- -
|
67
|
+
- - ~>
|
52
68
|
- !ruby/object:Gem::Version
|
53
|
-
version: 1.
|
69
|
+
version: 1.4.5
|
54
70
|
type: :runtime
|
55
71
|
prerelease: false
|
56
72
|
version_requirements: !ruby/object:Gem::Requirement
|
57
73
|
none: false
|
58
74
|
requirements:
|
59
|
-
- -
|
75
|
+
- - ~>
|
60
76
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
77
|
+
version: 1.4.5
|
62
78
|
description: Trims whitespace from response bodies sent through rack.
|
63
79
|
email:
|
64
80
|
- ben@kree.gr
|
@@ -90,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
106
|
version: '0'
|
91
107
|
segments:
|
92
108
|
- 0
|
93
|
-
hash:
|
109
|
+
hash: 3041786719630630150
|
94
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
111
|
none: false
|
96
112
|
requirements:
|
@@ -99,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
115
|
version: '0'
|
100
116
|
segments:
|
101
117
|
- 0
|
102
|
-
hash:
|
118
|
+
hash: 3041786719630630150
|
103
119
|
requirements: []
|
104
120
|
rubyforge_project:
|
105
121
|
rubygems_version: 1.8.23
|