mongrel_esi 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +14 -6
- data/doc/rdoc/classes/ESI/CParser.html +122 -0
- data/doc/rdoc/classes/ESI/Cache.html +178 -0
- data/doc/rdoc/classes/ESI/Cache.src/M000085.html +17 -0
- data/doc/rdoc/classes/ESI/Cache.src/M000086.html +20 -0
- data/doc/rdoc/classes/ESI/Config.html +333 -0
- data/doc/rdoc/classes/ESI/Config.src/M000052.html +18 -0
- data/doc/rdoc/classes/ESI/Config.src/M000053.html +18 -0
- data/doc/rdoc/classes/ESI/Config.src/M000054.html +35 -0
- data/doc/rdoc/classes/ESI/Config.src/M000055.html +38 -0
- data/doc/rdoc/classes/ESI/Config.src/M000056.html +23 -0
- data/doc/rdoc/classes/ESI/Config.src/M000057.html +18 -0
- data/doc/rdoc/classes/ESI/Config.src/M000058.html +20 -0
- data/doc/rdoc/classes/ESI/Config.src/M000059.html +18 -0
- data/doc/rdoc/classes/ESI/Config.src/M000060.html +24 -0
- data/doc/rdoc/classes/ESI/Config/CacheConfig.html +212 -0
- data/doc/rdoc/classes/ESI/Config/CacheConfig.src/M000064.html +19 -0
- data/doc/rdoc/classes/ESI/Config/CacheConfig.src/M000065.html +19 -0
- data/doc/rdoc/classes/ESI/Config/CacheConfig.src/M000066.html +18 -0
- data/doc/rdoc/classes/ESI/Config/CacheConfig.src/M000067.html +18 -0
- data/doc/rdoc/classes/ESI/Config/CacheConfig.src/M000068.html +18 -0
- data/doc/rdoc/classes/ESI/Config/ConfigRouter.html +187 -0
- data/doc/rdoc/classes/ESI/Config/ConfigRouter.src/M000061.html +19 -0
- data/doc/rdoc/classes/ESI/Config/ConfigRouter.src/M000062.html +21 -0
- data/doc/rdoc/classes/ESI/Config/ConfigRouter.src/M000063.html +21 -0
- data/doc/rdoc/classes/ESI/Dispatcher.html +172 -0
- data/doc/rdoc/classes/ESI/Dispatcher.src/M000087.html +22 -0
- data/doc/rdoc/classes/ESI/Dispatcher.src/M000088.html +18 -0
- data/doc/rdoc/classes/ESI/Fragment.html +218 -0
- data/doc/rdoc/classes/ESI/Fragment.src/M000100.html +20 -0
- data/doc/rdoc/classes/ESI/Fragment.src/M000101.html +18 -0
- data/doc/rdoc/classes/ESI/Fragment.src/M000102.html +18 -0
- data/doc/rdoc/classes/ESI/Invalidator.html +131 -0
- data/doc/rdoc/classes/ESI/Invalidator.src/M000004.html +41 -0
- data/doc/rdoc/classes/ESI/Log.html +221 -0
- data/doc/rdoc/classes/ESI/Log.src/M000030.html +18 -0
- data/doc/rdoc/classes/ESI/Log.src/M000031.html +18 -0
- data/doc/rdoc/classes/ESI/Log.src/M000032.html +18 -0
- data/doc/rdoc/classes/ESI/Log.src/M000033.html +18 -0
- data/doc/rdoc/classes/ESI/Log.src/M000034.html +18 -0
- data/doc/rdoc/classes/ESI/Log.src/M000035.html +18 -0
- data/doc/rdoc/classes/ESI/Log.src/M000036.html +18 -0
- data/doc/rdoc/classes/ESI/MemcachedCache.html +314 -0
- data/doc/rdoc/classes/ESI/MemcachedCache.src/M000040.html +24 -0
- data/doc/rdoc/classes/ESI/MemcachedCache.src/M000041.html +22 -0
- data/doc/rdoc/classes/ESI/MemcachedCache.src/M000042.html +19 -0
- data/doc/rdoc/classes/ESI/MemcachedCache.src/M000043.html +23 -0
- data/doc/rdoc/classes/ESI/MemcachedCache.src/M000044.html +18 -0
- data/doc/rdoc/classes/ESI/MemcachedCache.src/M000045.html +19 -0
- data/doc/rdoc/classes/ESI/MemcachedCache.src/M000046.html +18 -0
- data/doc/rdoc/classes/ESI/MemcachedCache.src/M000047.html +18 -0
- data/doc/rdoc/classes/ESI/MemcachedCache.src/M000048.html +17 -0
- data/doc/rdoc/classes/ESI/Parser.html +184 -0
- data/doc/rdoc/classes/ESI/Parser.src/M000049.html +51 -0
- data/doc/rdoc/classes/ESI/Parser.src/M000050.html +39 -0
- data/doc/rdoc/classes/ESI/Parser.src/M000051.html +19 -0
- data/doc/rdoc/classes/ESI/Processor.html +194 -0
- data/doc/rdoc/classes/ESI/Processor.src/M000037.html +26 -0
- data/doc/rdoc/classes/ESI/Processor.src/M000038.html +44 -0
- data/doc/rdoc/classes/ESI/Processor.src/M000039.html +26 -0
- data/doc/rdoc/classes/ESI/Proxy.html +304 -0
- data/doc/rdoc/classes/ESI/Proxy.src/M000069.html +20 -0
- data/doc/rdoc/classes/ESI/Proxy.src/M000070.html +55 -0
- data/doc/rdoc/classes/ESI/Proxy.src/M000071.html +53 -0
- data/doc/rdoc/classes/ESI/Proxy.src/M000072.html +25 -0
- data/doc/rdoc/classes/ESI/Proxy.src/M000073.html +19 -0
- data/doc/rdoc/classes/ESI/Proxy.src/M000074.html +27 -0
- data/doc/rdoc/classes/ESI/Proxy.src/M000075.html +18 -0
- data/doc/rdoc/classes/ESI/Proxy.src/M000076.html +28 -0
- data/doc/rdoc/classes/ESI/Proxy.src/M000077.html +29 -0
- data/doc/rdoc/classes/ESI/Response.html +250 -0
- data/doc/rdoc/classes/ESI/Response.src/M000078.html +23 -0
- data/doc/rdoc/classes/ESI/Response.src/M000079.html +18 -0
- data/doc/rdoc/classes/ESI/Response.src/M000080.html +21 -0
- data/doc/rdoc/classes/ESI/Response.src/M000081.html +20 -0
- data/doc/rdoc/classes/ESI/Response.src/M000082.html +25 -0
- data/doc/rdoc/classes/ESI/Response.src/M000083.html +18 -0
- data/doc/rdoc/classes/ESI/Response.src/M000084.html +33 -0
- data/doc/rdoc/classes/ESI/Router.html +212 -0
- data/doc/rdoc/classes/ESI/Router.src/M000098.html +36 -0
- data/doc/rdoc/classes/ESI/Router.src/M000099.html +25 -0
- data/doc/rdoc/classes/ESI/RubyCache.html +278 -0
- data/doc/rdoc/classes/ESI/RubyCache.src/M000089.html +20 -0
- data/doc/rdoc/classes/ESI/RubyCache.src/M000090.html +20 -0
- data/doc/rdoc/classes/ESI/RubyCache.src/M000091.html +20 -0
- data/doc/rdoc/classes/ESI/RubyCache.src/M000092.html +22 -0
- data/doc/rdoc/classes/ESI/RubyCache.src/M000093.html +18 -0
- data/doc/rdoc/classes/ESI/RubyCache.src/M000094.html +22 -0
- data/doc/rdoc/classes/ESI/RubyCache.src/M000095.html +18 -0
- data/doc/rdoc/classes/ESI/RubyCache.src/M000096.html +18 -0
- data/doc/rdoc/classes/ESI/RubyCache.src/M000097.html +18 -0
- data/doc/rdoc/classes/ESI/Tag.html +141 -0
- data/doc/rdoc/classes/ESI/Tag/Attempt.html +113 -0
- data/doc/rdoc/classes/ESI/Tag/Base.html +237 -0
- data/doc/rdoc/classes/ESI/Tag/Base.src/M000026.html +23 -0
- data/doc/rdoc/classes/ESI/Tag/Base.src/M000027.html +22 -0
- data/doc/rdoc/classes/ESI/Tag/Base.src/M000028.html +22 -0
- data/doc/rdoc/classes/ESI/Tag/Base.src/M000029.html +17 -0
- data/doc/rdoc/classes/ESI/Tag/Container.html +206 -0
- data/doc/rdoc/classes/ESI/Tag/Container.src/M000015.html +20 -0
- data/doc/rdoc/classes/ESI/Tag/Container.src/M000016.html +22 -0
- data/doc/rdoc/classes/ESI/Tag/Container.src/M000017.html +25 -0
- data/doc/rdoc/classes/ESI/Tag/Except.html +184 -0
- data/doc/rdoc/classes/ESI/Tag/Except.src/M000018.html +21 -0
- data/doc/rdoc/classes/ESI/Tag/Except.src/M000019.html +20 -0
- data/doc/rdoc/classes/ESI/Tag/Except.src/M000020.html +18 -0
- data/doc/rdoc/classes/ESI/Tag/Include.html +257 -0
- data/doc/rdoc/classes/ESI/Tag/Include.src/M000005.html +20 -0
- data/doc/rdoc/classes/ESI/Tag/Include.src/M000006.html +18 -0
- data/doc/rdoc/classes/ESI/Tag/Include.src/M000007.html +34 -0
- data/doc/rdoc/classes/ESI/Tag/Include.src/M000008.html +22 -0
- data/doc/rdoc/classes/ESI/Tag/Include.src/M000009.html +27 -0
- data/doc/rdoc/classes/ESI/Tag/Include.src/M000010.html +30 -0
- data/doc/rdoc/classes/ESI/Tag/Include.src/M000011.html +51 -0
- data/doc/rdoc/classes/ESI/Tag/Include/Request.html +199 -0
- data/doc/rdoc/classes/ESI/Tag/Include/Request.src/M000012.html +18 -0
- data/doc/rdoc/classes/ESI/Tag/Include/Request.src/M000013.html +44 -0
- data/doc/rdoc/classes/ESI/Tag/Include/Request/Error.html +155 -0
- data/doc/rdoc/classes/ESI/Tag/Include/Request/Error.src/M000014.html +19 -0
- data/doc/rdoc/classes/ESI/Tag/Invalidate.html +171 -0
- data/doc/rdoc/classes/ESI/Tag/Invalidate.src/M000023.html +19 -0
- data/doc/rdoc/classes/ESI/Tag/Invalidate.src/M000024.html +51 -0
- data/doc/rdoc/classes/ESI/Tag/Invalidate.src/M000025.html +19 -0
- data/doc/rdoc/classes/ESI/Tag/Try.html +154 -0
- data/doc/rdoc/classes/ESI/Tag/Try.src/M000021.html +38 -0
- data/doc/rdoc/classes/ESI/Tag/Try.src/M000022.html +18 -0
- data/doc/rdoc/classes/MultiDirHandler.html +198 -0
- data/doc/rdoc/classes/MultiDirHandler.src/M000001.html +20 -0
- data/doc/rdoc/classes/MultiDirHandler.src/M000002.html +28 -0
- data/doc/rdoc/classes/MultiDirHandler.src/M000003.html +22 -0
- data/doc/rdoc/created.rid +1 -0
- data/doc/rdoc/files/COPYING.html +167 -0
- data/doc/rdoc/files/LICENSE.html +605 -0
- data/doc/rdoc/files/README.html +359 -0
- data/doc/rdoc/files/ext/esi/common_rl.html +160 -0
- data/doc/rdoc/files/ext/esi/esi_parser_c.html +101 -0
- data/doc/rdoc/files/ext/esi/parser_c.html +101 -0
- data/doc/rdoc/files/ext/esi/parser_h.html +101 -0
- data/doc/rdoc/files/ext/esi/parser_rl.html +827 -0
- data/doc/rdoc/files/ext/esi/test/common_rl.html +160 -0
- data/doc/rdoc/files/ext/esi/test/parser_c.html +101 -0
- data/doc/rdoc/files/ext/esi/test/parser_h.html +101 -0
- data/doc/rdoc/files/ext/esi/test/parser_rl.html +827 -0
- data/doc/rdoc/files/ext/esi/test/sp_c.html +101 -0
- data/doc/rdoc/files/ext/esi/test/test_c.html +101 -0
- data/doc/rdoc/files/lib/esi/cache_rb.html +119 -0
- data/doc/rdoc/files/lib/esi/config_rb.html +114 -0
- data/doc/rdoc/files/lib/esi/dispatcher_rb.html +108 -0
- data/doc/rdoc/files/lib/esi/invalidator_rb.html +114 -0
- data/doc/rdoc/files/lib/esi/logger_rb.html +108 -0
- data/doc/rdoc/files/lib/esi/parser_rb.html +120 -0
- data/doc/rdoc/files/lib/esi/processor_rb.html +115 -0
- data/doc/rdoc/files/lib/esi/proxy_rb.html +123 -0
- data/doc/rdoc/files/lib/esi/response_rb.html +116 -0
- data/doc/rdoc/files/lib/esi/router_rb.html +107 -0
- data/doc/rdoc/files/lib/esi/tag/attempt_rb.html +114 -0
- data/doc/rdoc/files/lib/esi/tag/base_rb.html +114 -0
- data/doc/rdoc/files/lib/esi/tag/container_rb.html +115 -0
- data/doc/rdoc/files/lib/esi/tag/except_rb.html +114 -0
- data/doc/rdoc/files/lib/esi/tag/include_rb.html +116 -0
- data/doc/rdoc/files/lib/esi/tag/invalidate_rb.html +115 -0
- data/doc/rdoc/files/lib/esi/tag/try_rb.html +115 -0
- data/doc/rdoc/files/lib/esi/version_rb.html +101 -0
- data/doc/rdoc/files/lib/multi_dirhandler_rb.html +109 -0
- data/doc/rdoc/fr_class_index.html +53 -0
- data/doc/rdoc/fr_file_index.html +59 -0
- data/doc/rdoc/fr_method_index.html +128 -0
- data/doc/rdoc/index.html +24 -0
- data/doc/rdoc/rdoc-style.css +208 -0
- data/ext/esi/esi_parser.c +12 -1
- data/ext/esi/parser.c +492 -3927
- data/ext/esi/parser.rl +83 -14
- data/ext/esi/test/parser.c +1587 -367
- data/ext/esi/test/parser.rl +83 -14
- data/ext/esi/test/sp.c +125 -0
- data/ext/esi/test/test.c +198 -6
- data/lib/esi/cache.rb +5 -8
- data/lib/esi/config.rb +3 -3
- data/lib/esi/dispatcher.rb +2 -4
- data/lib/esi/parser.rb +26 -13
- data/lib/esi/processor.rb +13 -35
- data/lib/esi/proxy.rb +113 -44
- data/lib/esi/response.rb +23 -55
- data/lib/esi/router.rb +0 -11
- data/lib/esi/tag/attempt.rb +2 -1
- data/lib/esi/tag/base.rb +1 -24
- data/lib/esi/tag/container.rb +40 -0
- data/lib/esi/tag/except.rb +3 -1
- data/lib/esi/tag/include.rb +53 -62
- data/lib/esi/tag/try.rb +16 -18
- data/lib/esi/version.rb +9 -0
- data/test/integration/handler_test.rb +49 -12
- data/test/integration/help.rb +12 -0
- data/test/load_test.rb +8 -4
- data/test/load_test_ab.rb +8 -0
- data/test/sample.html +31 -0
- data/test/unit/help.rb +12 -8
- data/test/unit/include_request_test.rb +14 -21
- data/test/unit/parser_test.rb +2 -1
- data/test/unit/response_test.rb +4 -8
- data/tools/rakehelp.rb +1 -1
- metadata +216 -5
data/lib/esi/router.rb
CHANGED
@@ -23,7 +23,6 @@ module ESI
|
|
23
23
|
# default:
|
24
24
|
# host: 127.0.01
|
25
25
|
# port: 3001
|
26
|
-
# cache_ttl: 300
|
27
26
|
#
|
28
27
|
# This example will cache all requests for 300 seconds, by default.
|
29
28
|
#
|
@@ -72,16 +71,6 @@ module ESI
|
|
72
71
|
"http://" + (config[:host] + ":" + (config[:port] || "").to_s + "/" + request_uri).squeeze("/")
|
73
72
|
end
|
74
73
|
|
75
|
-
def cache_ttl( request_uri )
|
76
|
-
return 600 if request_uri.match(/http:\/\//) # default cache for absolute URLs
|
77
|
-
# locate the first entry to match the given uri
|
78
|
-
config = @hosts.find do |cfg|
|
79
|
-
Regexp.new(cfg[:match_url]).match(request_uri)
|
80
|
-
end
|
81
|
-
config = @default unless config
|
82
|
-
(config[:cache_ttl] || 600).to_i
|
83
|
-
end
|
84
|
-
|
85
74
|
end
|
86
75
|
|
87
76
|
end
|
data/lib/esi/tag/attempt.rb
CHANGED
data/lib/esi/tag/base.rb
CHANGED
@@ -9,7 +9,6 @@ module ESI
|
|
9
9
|
attr_reader :attributes, :children, :name, :closed, :cache
|
10
10
|
|
11
11
|
include ESI::Log
|
12
|
-
extend ESI::Log
|
13
12
|
|
14
13
|
def initialize(router,headers,http_params,name,attrs,cache)
|
15
14
|
@router = router
|
@@ -17,16 +16,12 @@ module ESI
|
|
17
16
|
@http_params = http_params
|
18
17
|
@attributes = attrs
|
19
18
|
@cache = cache
|
20
|
-
@children = []
|
21
19
|
@name = name
|
22
|
-
@unclosed = nil
|
23
|
-
@closed = false
|
24
20
|
end
|
25
21
|
|
26
22
|
def self.create(router,headers,http_params,tag_name,attrs,cache)
|
27
|
-
tag_name.gsub!(/esi:/,'')
|
28
23
|
raise "Unsupport ESI tag: #{tag_name}" unless Validate.include?(tag_name)
|
29
|
-
eval(tag_name.capitalize).new(router,headers,http_params,tag_name,attrs,cache)
|
24
|
+
eval(tag_name.sub(/esi:/,'').capitalize).new(router,headers,http_params,tag_name,attrs,cache)
|
30
25
|
rescue => e
|
31
26
|
log_debug "Failed while creating tag: #{tag_name}, with error: #{e.message}"
|
32
27
|
raise e
|
@@ -41,24 +36,6 @@ module ESI
|
|
41
36
|
end
|
42
37
|
|
43
38
|
def close( output, options = {} )
|
44
|
-
@closed = true
|
45
|
-
end
|
46
|
-
|
47
|
-
def close_child( output, name )
|
48
|
-
name = name.gsub(/esi:/,'')
|
49
|
-
if @unclosed and @unclosed.name == name
|
50
|
-
@unclosed.close( output )
|
51
|
-
@unclosed = nil
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def add_child(tag)
|
56
|
-
if @unclosed
|
57
|
-
@unclosed.add_child(tag)
|
58
|
-
else
|
59
|
-
@unclosed = tag
|
60
|
-
@children << tag
|
61
|
-
end
|
62
39
|
end
|
63
40
|
|
64
41
|
# :startdoc:
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Copyright (c) 2008 Todd A. Fisher
|
2
|
+
# see LICENSE
|
3
|
+
require 'esi/logger'
|
4
|
+
require 'esi/tag/base'
|
5
|
+
|
6
|
+
module ESI
|
7
|
+
module Tag
|
8
|
+
class Container < ESI::Tag::Base
|
9
|
+
include ESI::Log
|
10
|
+
extend ESI::Log
|
11
|
+
attr_reader :children, :name, :closed, :cache
|
12
|
+
|
13
|
+
def initialize(router,headers,http_params,name,attrs,cache)
|
14
|
+
super
|
15
|
+
@children = []
|
16
|
+
@unclosed = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def close_child( output, name )
|
20
|
+
name = name.sub(/esi:/,'')
|
21
|
+
if @unclosed and @unclosed.name == name
|
22
|
+
@unclosed.close( output )
|
23
|
+
@unclosed = nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_child(tag)
|
28
|
+
if @unclosed
|
29
|
+
#puts "add as child of(#{self.name}): #{tag.name} #{tag.attributes.inspect} to #{@unclosed.name}"
|
30
|
+
@unclosed.add_child(tag)
|
31
|
+
else
|
32
|
+
#puts "add: #{tag.name} #{tag.attributes.inspect} to #{self.name}"
|
33
|
+
@unclosed = tag if tag.respond_to?(:add_child)
|
34
|
+
@children << tag
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/esi/tag/except.rb
CHANGED
data/lib/esi/tag/include.rb
CHANGED
@@ -34,34 +34,34 @@ module ESI
|
|
34
34
|
@headers = forward_headers
|
35
35
|
end
|
36
36
|
|
37
|
-
def request(
|
38
|
-
uri = URI.parse(
|
37
|
+
def request(url, timeout = 1, alt_failover=nil, follow_limit=3)
|
38
|
+
uri = URI.parse(url)
|
39
39
|
Net::HTTP.start(uri.host, uri.port) do|http|
|
40
40
|
http.read_timeout = timeout if timeout and timeout > 0
|
41
41
|
rp = uri.query ? "#{uri.path}?#{uri.query}" : uri.path
|
42
42
|
http.request_get( rp, @headers ) do|response|
|
43
43
|
case response
|
44
44
|
when Net::HTTPSuccess
|
45
|
-
yield true, response,
|
45
|
+
yield true, response, url
|
46
46
|
when Net::HTTPRedirection
|
47
47
|
ir = Request.new(@headers)
|
48
|
-
ir.request(
|
49
|
-
yield s, r,
|
48
|
+
ir.request(response['location'], timeout, alt_failover, follow_limit - 1) do|s,r|
|
49
|
+
yield s, r, response['location']
|
50
50
|
end
|
51
51
|
else
|
52
52
|
if alt_failover
|
53
53
|
ir = Request.new(@headers)
|
54
54
|
ir.request(alt_failover, timeout, nil, follow_limit) do|s,r|
|
55
|
-
yield s, r,
|
55
|
+
yield s, r, alt_failover
|
56
56
|
end
|
57
57
|
else
|
58
|
-
yield false, Error.new("Failed to request fragment: #{uri.scheme}://#{uri.host}:#{uri.port}#{uri.path}", response),
|
58
|
+
yield false, Error.new("Failed to request fragment: #{uri.scheme}://#{uri.host}:#{uri.port}#{uri.path}", response), url
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
63
63
|
rescue Timeout::Error => e
|
64
|
-
yield false, Error.new("Failed to request fragment: #{uri.scheme}://#{uri.host}:#{uri.port}#{uri.path}, timeout error: #{e.message}", nil),
|
64
|
+
yield false, Error.new("Failed to request fragment: #{uri.scheme}://#{uri.host}:#{uri.port}#{uri.path}, timeout error: #{e.message}", nil), url
|
65
65
|
end
|
66
66
|
|
67
67
|
end
|
@@ -93,7 +93,7 @@ module ESI
|
|
93
93
|
if @cache.cached?( src, @http_params )
|
94
94
|
send_from_cache( src )
|
95
95
|
else
|
96
|
-
|
96
|
+
send_from_origin( src, alt, raise_on_error )
|
97
97
|
end
|
98
98
|
|
99
99
|
end
|
@@ -102,75 +102,29 @@ module ESI
|
|
102
102
|
def prepare_parser
|
103
103
|
if parse_fragment?
|
104
104
|
@parser = ESI::Parser.new( @output, @router, @cache, @max_depth )
|
105
|
-
@parser.prepare( @headers, @http_params )
|
106
|
-
if @parser.response.active_buffer.closed_write?
|
107
|
-
@parser.response.open_active_buffer
|
108
|
-
@parser.response.send
|
109
|
-
end
|
110
|
-
@parser.response.active_buffer << chars
|
111
|
-
end
|
105
|
+
@parser.prepare( @headers, @http_params )
|
112
106
|
@parser.depth = (@depth+1) # increment the depth
|
113
107
|
end
|
114
108
|
end
|
115
109
|
|
116
110
|
def send_from_cache( src )
|
117
111
|
cached_fragment = @cache.get( src, @headers ).body
|
118
|
-
log_request "C"
|
119
|
-
if parse_fragment?
|
112
|
+
#log_request "C"
|
120
113
|
|
114
|
+
if parse_fragment? and cached_fragment.match(/<esi:/)
|
121
115
|
@parser.process cached_fragment
|
122
116
|
@parser.finish
|
123
|
-
|
124
117
|
else
|
125
118
|
@output << cached_fragment
|
126
119
|
end
|
127
120
|
|
128
121
|
end
|
129
122
|
|
130
|
-
def
|
131
|
-
|
132
|
-
|
133
|
-
ir.request(src, @attributes['timeout'].to_i, alt ) do|status,response,uri|
|
123
|
+
def send_from_origin( src, alt, raise_on_error )
|
124
|
+
#log_request "R"
|
125
|
+
Request.new(@http_params).request(src, @attributes['timeout'].to_i, alt ) do|status,response,url|
|
134
126
|
if status
|
135
|
-
|
136
|
-
# reprocess the esi:include vars even for cached content, this way we can have cached content
|
137
|
-
# with HTTP_COOKIE vars and avoid re-requesting content
|
138
|
-
cache_buffer = ""
|
139
|
-
response.read_body do|s|
|
140
|
-
cache_buffer << s
|
141
|
-
if parse_fragment?
|
142
|
-
@parser.process s
|
143
|
-
else
|
144
|
-
@output << s
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
if parse_fragment?
|
149
|
-
@parser.finish
|
150
|
-
end
|
151
|
-
|
152
|
-
if src != uri # these won't be equal if the fragment followed a redirect or used the alt condition
|
153
|
-
if uri.query
|
154
|
-
request_uri = "#{uri.scheme}://#{uri.host}:#{uri.port}#{uri.path}?#{uri.query}"
|
155
|
-
else
|
156
|
-
request_uri = "#{uri.scheme}://#{uri.host}:#{uri.port}#{uri.path}"
|
157
|
-
end
|
158
|
-
else
|
159
|
-
request_uri = src
|
160
|
-
end
|
161
|
-
|
162
|
-
cache_ttl = (@attributes['max-age']||600) # defaults to 600... maybe should have this be configurable?
|
163
|
-
if cache_ttl.respond_to?(:match) and cache_ttl.match(/\+/)
|
164
|
-
total=0
|
165
|
-
cache_ttl.split('+').each {|comp| total+=comp.to_i}
|
166
|
-
cache_ttl = total
|
167
|
-
else
|
168
|
-
cache_ttl = cache_ttl.to_i
|
169
|
-
end
|
170
|
-
|
171
|
-
@cache.put(request_uri, @http_params, cache_ttl, cache_buffer )
|
172
|
-
#log_request "R #{src} #{Time.now - timer}\n"
|
173
|
-
|
127
|
+
process_successful_response( url, status, response )
|
174
128
|
else
|
175
129
|
# error/ check if the include has an onerror specifier
|
176
130
|
return if @attributes['onerror'] == 'continue'
|
@@ -182,6 +136,43 @@ module ESI
|
|
182
136
|
end
|
183
137
|
end
|
184
138
|
|
139
|
+
def process_successful_response( url, status, response )
|
140
|
+
# NOTE: it's important that we cache the unprocessed markup, because we need to
|
141
|
+
# reprocess the esi:include vars even for cached content, this way we can have cached content
|
142
|
+
# with HTTP_COOKIE vars and avoid re-requesting content
|
143
|
+
cache_buffer = ""
|
144
|
+
if parse_fragment?
|
145
|
+
response.read_body do|s|
|
146
|
+
cache_buffer << s
|
147
|
+
end
|
148
|
+
if cache_buffer.match(/<esi:/)
|
149
|
+
@parser.process cache_buffer
|
150
|
+
@parser.finish
|
151
|
+
else
|
152
|
+
@output << cache_buffer
|
153
|
+
end
|
154
|
+
else
|
155
|
+
response.read_body do|s|
|
156
|
+
cache_buffer << s
|
157
|
+
end
|
158
|
+
@output << cache_buffer
|
159
|
+
end
|
160
|
+
|
161
|
+
request_uri = url
|
162
|
+
|
163
|
+
cache_ttl = (@attributes['max-age']||600) # defaults to 600... maybe should have this be configurable?
|
164
|
+
if cache_ttl.respond_to?(:match) and cache_ttl.match(/\+/)
|
165
|
+
total=0
|
166
|
+
cache_ttl.split('+').each {|comp| total+=comp.to_i}
|
167
|
+
cache_ttl = total
|
168
|
+
else
|
169
|
+
cache_ttl = cache_ttl.to_i
|
170
|
+
end
|
171
|
+
|
172
|
+
@cache.put(request_uri, @http_params, cache_ttl, cache_buffer )
|
173
|
+
#log_request "R #{src} #{Time.now - timer}\n"
|
174
|
+
end
|
175
|
+
|
185
176
|
|
186
177
|
end
|
187
178
|
|
data/lib/esi/tag/try.rb
CHANGED
@@ -2,34 +2,32 @@
|
|
2
2
|
# see LICENSE
|
3
3
|
|
4
4
|
require 'esi/logger'
|
5
|
+
require 'esi/tag/container'
|
5
6
|
|
6
7
|
module ESI
|
7
8
|
module Tag
|
8
|
-
class Try <
|
9
|
-
|
10
|
-
|
9
|
+
class Try < Container
|
10
|
+
|
11
11
|
def close( output )
|
12
12
|
super(output)
|
13
13
|
begin
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
@children.each do |tag|
|
15
|
+
if tag.name == "attempt"
|
16
|
+
tag.children.each do|ctag|
|
17
|
+
ctag.close( output, :raise => true )
|
18
|
+
end
|
19
|
+
end
|
17
20
|
end
|
18
21
|
rescue => e
|
19
22
|
log_error e.message
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
@children.each do |tag|
|
24
|
+
if tag.name == "except"
|
25
|
+
tag.children.each_with_index do|ctag,index|
|
26
|
+
output << tag.buffers[index]
|
27
|
+
ctag.close( output )
|
28
|
+
end
|
29
|
+
output << tag.buffers[tag.children.size]
|
26
30
|
end
|
27
|
-
tag.close( output )
|
28
|
-
end
|
29
|
-
if( output.respond_to?('<<') )
|
30
|
-
output << except.buffers[except.children.size]
|
31
|
-
else
|
32
|
-
output.call except.buffers[except.children.size]
|
33
31
|
end
|
34
32
|
end
|
35
33
|
end
|
data/lib/esi/version.rb
ADDED
@@ -15,16 +15,48 @@ class HandlerTest < Test::Unit::TestCase
|
|
15
15
|
end
|
16
16
|
check_status results, String
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
|
+
def simple_response_assertions(res)
|
20
|
+
assert_not_nil res
|
21
|
+
assert_not_nil res.header
|
22
|
+
assert_not_nil res.body
|
23
|
+
assert_equal Net::HTTPOK, res.header.class
|
24
|
+
assert_match '<html>', res.body, "Missing document head"
|
25
|
+
assert_match $fragment_test1, res.body, "Fragment not found"
|
26
|
+
assert_match $fragment_test2, res.body, "Fragment not found"
|
27
|
+
assert_match '</html>', res.body, "Missing document footer"
|
28
|
+
assert_equal %{<html>\n<head>\n</head>\n<body>\n <h1>This is a test document</h1>\n \n valid\n \n <div>test1</div>\n\n \n \n <div>test2</div>\n\n</body>\n</html>\n}, res.body
|
29
|
+
assert_no_match /<esi:/, res.body # assert there are no esi tags in the result
|
30
|
+
end
|
31
|
+
|
19
32
|
def test_simple_esi
|
20
33
|
Net::HTTP.start("localhost", 9997) do |h|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
34
|
+
res = h.get("/esi_test_content.html")
|
35
|
+
simple_response_assertions(res)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_simple_esi_http10
|
40
|
+
Net::HTTP.start("localhost", 9997) do |h|
|
41
|
+
res = h.get("/esi_test_content.html",{"VERSION" => "HTTP/1.0"})
|
42
|
+
simple_response_assertions(res)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_page_surrogate_control_max_age
|
47
|
+
Net::HTTP.start("localhost", 9997) do |h|
|
48
|
+
res = h.get("/surrogate-test",{"Surrogate-Control" => %{max-age=10, content="ESI/1.0"}})
|
49
|
+
simple_response_assertions(res)
|
50
|
+
assert res.header.to_hash.key?("transfer-encoding")
|
51
|
+
assert !res.header.to_hash.key?("content-length")
|
52
|
+
assert_equal "chunked", res.header["transfer-encoding"]
|
53
|
+
end
|
54
|
+
Net::HTTP.start("localhost", 9997) do |h|
|
55
|
+
res = h.get("/surrogate-test",{"Surrogate-Control" => %{max-age=10, content="ESI/1.0"}})
|
56
|
+
simple_response_assertions(res)
|
57
|
+
assert !res.header.to_hash.key?("transfer-encoding")
|
58
|
+
assert res.header.to_hash.key?("content-length")
|
59
|
+
assert_equal "156", res.header["content-length"]
|
28
60
|
end
|
29
61
|
end
|
30
62
|
|
@@ -36,6 +68,9 @@ class HandlerTest < Test::Unit::TestCase
|
|
36
68
|
assert_not_nil req.body
|
37
69
|
assert_equal Net::HTTPOK, req.header.class
|
38
70
|
assert_match $fragment_test1, req.body, "Fragment not found"
|
71
|
+
assert_match "</html>", req.body, "End tag not found"
|
72
|
+
assert_no_match /<p>sorry<\/p>/, req.body, "Should not see any fragment failures"
|
73
|
+
assert_no_match /<esi:/, req.body # assert there are no esi tags in the result
|
39
74
|
# should have 37 fragments
|
40
75
|
count = 0
|
41
76
|
req.body.scan $fragment_test1 do|m|
|
@@ -87,7 +122,7 @@ class HandlerTest < Test::Unit::TestCase
|
|
87
122
|
assert_equal "/esi_test_content.html", res["Location"]
|
88
123
|
end
|
89
124
|
end
|
90
|
-
|
125
|
+
|
91
126
|
# test that we're including http headers as part of the request fragment cache
|
92
127
|
def test_ajax_caching
|
93
128
|
# start by making the request using the X-Requested-With Header
|
@@ -196,9 +231,11 @@ class HandlerTest < Test::Unit::TestCase
|
|
196
231
|
assert_not_nil res.body
|
197
232
|
#puts res.body
|
198
233
|
assert_equal Net::HTTPOK, res.header.class, res.body
|
199
|
-
|
200
|
-
assert_match
|
201
|
-
assert_match
|
234
|
+
assert_match "<html>", res.body
|
235
|
+
assert_match "<div>test1</div>", res.body, "Normal esi include tags failed"
|
236
|
+
assert_match "<div>test1</div>", res.body, "Normal esi include tags failed"
|
237
|
+
assert_match %{<a href="www.akamai.com">www.example.com </a>}, res.body, "Static Failover failed"
|
238
|
+
assert_match "</html>", res.body
|
202
239
|
end
|
203
240
|
end
|
204
241
|
|