rack_ssi 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/lib/rack_ssi.rb +2 -2
- data/lib/ssi_processor.rb +8 -4
- data/rack-ssi.gemspec +3 -3
- data/spec/ssi_processor_spec.rb +36 -41
- metadata +14 -17
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 899d18689b60d6ff2533d84b1f94c0a04d1a90f7
|
4
|
+
data.tar.gz: 9f7105dc0d3b7da27fa9e0bc643b0c319089c15d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dc1c5645e72223e7275d06c24e3c747ad73587786d45b605ad7120c7c040975885fd420e9f241809cc5f7d3b2dfc78783a940313b991112f1c58c3a143110c64
|
7
|
+
data.tar.gz: d491818ea3a54e3d4437343455073febb1865a585d4e2c0f85d1b013379ffce8723923cd0f350f41b98aadd6791e5f9de16fb0ec54a5762b6019fe87a9e7833f
|
data/.gitignore
CHANGED
data/lib/rack_ssi.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'compatibility'
|
2
2
|
require 'ssi_processor'
|
3
|
-
require '
|
3
|
+
require 'httparty'
|
4
4
|
require 'logger'
|
5
5
|
|
6
6
|
module Rack
|
@@ -21,7 +21,7 @@ module Rack
|
|
21
21
|
return unprocessed unless headers["Content-Type"] && headers["Content-Type"].include?("text/html")
|
22
22
|
return unprocessed unless status == 200
|
23
23
|
|
24
|
-
ssi = Rack::SSIProcessor.new
|
24
|
+
ssi = Rack::SSIProcessor.new(env)
|
25
25
|
ssi.locations = @locations
|
26
26
|
ssi.logger = logger(env) if @logging
|
27
27
|
new_body = ssi.process(body)
|
data/lib/ssi_processor.rb
CHANGED
@@ -2,6 +2,10 @@ module Rack
|
|
2
2
|
class SSIProcessor
|
3
3
|
|
4
4
|
attr_accessor :logger, :locations
|
5
|
+
|
6
|
+
def initialize(env)
|
7
|
+
@env = env
|
8
|
+
end
|
5
9
|
|
6
10
|
def process(body)
|
7
11
|
# see http://wiki.nginx.org/HttpSsiModule
|
@@ -51,10 +55,10 @@ module Rack
|
|
51
55
|
|
52
56
|
def _get(url)
|
53
57
|
_info "fetching #{url}"
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
+
headers = @env['HTTP_COOKIE'] ? {'Cookie' => @env['HTTP_COOKIE']} : {}
|
59
|
+
response = HTTParty.get(url, headers: headers)
|
60
|
+
_error "error fetching #{url}: #{response.code} response" if response.code != 200
|
61
|
+
[response.code, response.headers, response.body]
|
58
62
|
end
|
59
63
|
|
60
64
|
def _info(message)
|
data/rack-ssi.gemspec
CHANGED
@@ -8,13 +8,13 @@ Gem::Specification.new do |gem|
|
|
8
8
|
Directives currently supported: 'block' and 'include'
|
9
9
|
EOS
|
10
10
|
gem.summary = "Rack middleware for processing SSI based on the nginx HttpSsiModule."
|
11
|
-
gem.homepage = "https://github.com/
|
11
|
+
gem.homepage = "https://github.com/uswitch/rack-ssi"
|
12
12
|
|
13
13
|
gem.files = `git ls-files`.split($\)
|
14
14
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
15
15
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
16
16
|
gem.name = "rack_ssi"
|
17
17
|
gem.require_paths = ["lib"]
|
18
|
-
gem.version = "0.0.
|
19
|
-
gem.add_dependency "
|
18
|
+
gem.version = "0.0.6"
|
19
|
+
gem.add_dependency "httparty"
|
20
20
|
end
|
data/spec/ssi_processor_spec.rb
CHANGED
@@ -4,6 +4,11 @@ require File.expand_path('../spec_helper', __FILE__)
|
|
4
4
|
|
5
5
|
describe Rack::SSIProcessor do
|
6
6
|
|
7
|
+
before :each do
|
8
|
+
env = double("env", :[] => "")
|
9
|
+
@processor = Rack::SSIProcessor.new(env)
|
10
|
+
end
|
11
|
+
|
7
12
|
describe "#process_block" do
|
8
13
|
it "should yield block directives and strip them out of the html" do
|
9
14
|
html = <<-eos
|
@@ -24,10 +29,9 @@ describe Rack::SSIProcessor do
|
|
24
29
|
</html>
|
25
30
|
eos
|
26
31
|
|
27
|
-
ssi = Rack::SSIProcessor.new
|
28
32
|
blocks = []
|
29
33
|
|
30
|
-
processed =
|
34
|
+
processed = @processor.process_block(html) {|block| blocks << block}
|
31
35
|
|
32
36
|
processed.gsub(/\s+/, "").should == expected
|
33
37
|
blocks.should == [["shush", ""], ["shouty", "<h1>ERROR!</h1>"]]
|
@@ -51,10 +55,9 @@ describe Rack::SSIProcessor do
|
|
51
55
|
</html>
|
52
56
|
eos
|
53
57
|
|
54
|
-
ssi = Rack::SSIProcessor.new
|
55
58
|
blocks = []
|
56
59
|
|
57
|
-
processed =
|
60
|
+
processed = @processor.process_block(html) {|block| blocks << block}
|
58
61
|
|
59
62
|
processed.gsub(/\s+/, "").should == expected
|
60
63
|
blocks.should == [["shush", ""], ["shouty", "<h1>ERROR!</h1>"]]
|
@@ -82,11 +85,10 @@ describe Rack::SSIProcessor do
|
|
82
85
|
</html>
|
83
86
|
eos
|
84
87
|
|
85
|
-
|
86
|
-
|
87
|
-
ssi.stub(:fetch).with("/some/other/location").and_return([200, {}, "<p>some more content</p>"])
|
88
|
+
@processor.stub(:fetch).with("/some/location").and_return([200, {}, "<p>some content</p>"])
|
89
|
+
@processor.stub(:fetch).with("/some/other/location").and_return([200, {}, "<p>some more content</p>"])
|
88
90
|
|
89
|
-
processed =
|
91
|
+
processed = @processor.process_include(html, {})
|
90
92
|
|
91
93
|
processed.gsub(/\s+/, "").should == expected
|
92
94
|
end
|
@@ -109,10 +111,9 @@ describe Rack::SSIProcessor do
|
|
109
111
|
</html>
|
110
112
|
eos
|
111
113
|
|
112
|
-
|
113
|
-
ssi.stub(:fetch).with("/some/other/location_from_haml").and_return([200, {}, "<p>some content from haml</p>"])
|
114
|
+
@processor.stub(:fetch).with("/some/other/location_from_haml").and_return([200, {}, "<p>some content from haml</p>"])
|
114
115
|
|
115
|
-
processed =
|
116
|
+
processed = @processor.process_include(html, {})
|
116
117
|
|
117
118
|
processed.gsub(/\s+/, "").should == expected
|
118
119
|
end
|
@@ -136,10 +137,9 @@ describe Rack::SSIProcessor do
|
|
136
137
|
</html>
|
137
138
|
eos
|
138
139
|
|
139
|
-
|
140
|
-
ssi.stub(:fetch).with("/some/broken/location").and_return([200, {}, ""])
|
140
|
+
@processor.stub(:fetch).with("/some/broken/location").and_return([200, {}, ""])
|
141
141
|
|
142
|
-
processed =
|
142
|
+
processed = @processor.process_include(html, {"oops" => "<p>oops, something went wrong!</p>"})
|
143
143
|
|
144
144
|
processed.gsub(/\s+/, "").should == expected
|
145
145
|
end
|
@@ -153,10 +153,9 @@ describe Rack::SSIProcessor do
|
|
153
153
|
</html>
|
154
154
|
eos
|
155
155
|
|
156
|
-
|
157
|
-
ssi.stub(:fetch).with("/some/broken/location").and_return([200, {}, ""])
|
156
|
+
@processor.stub(:fetch).with("/some/broken/location").and_return([200, {}, ""])
|
158
157
|
|
159
|
-
processed =
|
158
|
+
processed = @processor.process_include(html, {})
|
160
159
|
|
161
160
|
processed.gsub(/\s+/, "").should == "<html><body></body></html>"
|
162
161
|
end
|
@@ -179,11 +178,10 @@ describe Rack::SSIProcessor do
|
|
179
178
|
</body>
|
180
179
|
</html>
|
181
180
|
eos
|
182
|
-
|
183
|
-
ssi = Rack::SSIProcessor.new
|
184
|
-
ssi.stub(:fetch).with("/some/broken/location").and_return([500, {}, "<crap>"])
|
185
181
|
|
186
|
-
|
182
|
+
@processor.stub(:fetch).with("/some/broken/location").and_return([500, {}, "<crap>"])
|
183
|
+
|
184
|
+
processed = @processor.process_include(html, {"oops" => "<p>oops, something went wrong!</p>"})
|
187
185
|
|
188
186
|
processed.gsub(/\s+/, "").should == expected
|
189
187
|
end
|
@@ -196,11 +194,10 @@ describe Rack::SSIProcessor do
|
|
196
194
|
</body>
|
197
195
|
</html>
|
198
196
|
eos
|
199
|
-
|
200
|
-
ssi = Rack::SSIProcessor.new
|
201
|
-
ssi.stub(:fetch).with("/some/broken/location").and_return([500, {}, "<bang>"])
|
202
197
|
|
203
|
-
|
198
|
+
@processor.stub(:fetch).with("/some/broken/location").and_return([500, {}, "<bang>"])
|
199
|
+
|
200
|
+
processed = @processor.process_include(html, {})
|
204
201
|
|
205
202
|
processed.gsub(/\s+/, "").should == "<html><body><bang></body></html>"
|
206
203
|
end
|
@@ -224,10 +221,9 @@ describe Rack::SSIProcessor do
|
|
224
221
|
</html>
|
225
222
|
eos
|
226
223
|
|
227
|
-
|
228
|
-
ssi.stub(:fetch).with("/some/location").and_return([200, {}, "<p>€254</p>".force_encoding("ASCII-8BIT")])
|
224
|
+
@processor.stub(:fetch).with("/some/location").and_return([200, {}, "<p>€254</p>".force_encoding("ASCII-8BIT")])
|
229
225
|
|
230
|
-
processed =
|
226
|
+
processed = @processor.process_include(html, {})
|
231
227
|
processed.gsub(/\s+/, "").should == expected
|
232
228
|
end
|
233
229
|
end
|
@@ -235,25 +231,25 @@ describe Rack::SSIProcessor do
|
|
235
231
|
|
236
232
|
describe "#fetch" do
|
237
233
|
it "should resolve locations by exact match first" do
|
238
|
-
|
239
|
-
ssi.locations = {
|
234
|
+
@processor.locations = {
|
240
235
|
/\/pants/ => "http://host1",
|
241
236
|
"/pants" => "http://host2"
|
242
237
|
}
|
243
238
|
|
244
|
-
|
245
|
-
|
239
|
+
HTTParty.stub(:get).and_return(double("response", code: 200, headers: [], body: ''))
|
240
|
+
HTTParty.should_receive(:get).with("http://host2/pants", anything)
|
241
|
+
@processor.fetch("/pants")
|
242
|
+
|
246
243
|
end
|
247
244
|
|
248
245
|
it "should resolve locations by regex if no exact match" do
|
249
|
-
|
250
|
-
ssi.locations = {
|
246
|
+
@processor.locations = {
|
251
247
|
/^\/pants\/.*/ => "http://host1",
|
252
248
|
"/pants" => "http://host2"
|
253
249
|
}
|
254
|
-
|
255
|
-
|
256
|
-
|
250
|
+
HTTParty.stub(:get).and_return(double("response", code: 200, headers: [], body: ''))
|
251
|
+
HTTParty.should_receive(:get).with("http://host1/pants/on/fire", anything)
|
252
|
+
@processor.fetch("/pants/on/fire")
|
257
253
|
end
|
258
254
|
end
|
259
255
|
|
@@ -266,11 +262,10 @@ describe Rack::SSIProcessor do
|
|
266
262
|
'<!--# include virtual="/includes/header" -->',
|
267
263
|
'</body></html>'
|
268
264
|
]
|
269
|
-
|
270
|
-
|
271
|
-
ssi.stub(:fetch).with("/includes/header").and_return([200, {}, "<h1>Hello</h1>"])
|
265
|
+
@processor.stub(:fetch).with("/includes/broken").and_return([500, {}, "<p>pants!</p>"])
|
266
|
+
@processor.stub(:fetch).with("/includes/header").and_return([200, {}, "<h1>Hello</h1>"])
|
272
267
|
|
273
|
-
|
268
|
+
@processor.process(body).join.should == "<html><body><p>ERROR!</p><h1>Hello</h1></body></html>"
|
274
269
|
end
|
275
270
|
end
|
276
271
|
|
metadata
CHANGED
@@ -1,34 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack_ssi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.6
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Thibaut Sacreste
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-04-07 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
14
|
+
name: httparty
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
|
-
description:
|
31
|
-
|
27
|
+
description: |2
|
28
|
+
Rack middleware for processing SSI based on the nginx HttpSsiModule.
|
29
|
+
Directives currently supported: 'block' and 'include'
|
32
30
|
email:
|
33
31
|
- thibaut.sacreste@gmail.com
|
34
32
|
executables: []
|
@@ -47,29 +45,28 @@ files:
|
|
47
45
|
- spec/rack_ssi_spec.rb
|
48
46
|
- spec/spec_helper.rb
|
49
47
|
- spec/ssi_processor_spec.rb
|
50
|
-
homepage: https://github.com/
|
48
|
+
homepage: https://github.com/uswitch/rack-ssi
|
51
49
|
licenses: []
|
50
|
+
metadata: {}
|
52
51
|
post_install_message:
|
53
52
|
rdoc_options: []
|
54
53
|
require_paths:
|
55
54
|
- lib
|
56
55
|
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
56
|
requirements:
|
59
|
-
- -
|
57
|
+
- - '>='
|
60
58
|
- !ruby/object:Gem::Version
|
61
59
|
version: '0'
|
62
60
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
-
none: false
|
64
61
|
requirements:
|
65
|
-
- -
|
62
|
+
- - '>='
|
66
63
|
- !ruby/object:Gem::Version
|
67
64
|
version: '0'
|
68
65
|
requirements: []
|
69
66
|
rubyforge_project:
|
70
|
-
rubygems_version:
|
67
|
+
rubygems_version: 2.0.3
|
71
68
|
signing_key:
|
72
|
-
specification_version:
|
69
|
+
specification_version: 4
|
73
70
|
summary: Rack middleware for processing SSI based on the nginx HttpSsiModule.
|
74
71
|
test_files:
|
75
72
|
- spec/rack_ssi_spec.rb
|