Class: ESI::Tag::Include::Request
- Inherits:
-
Object
- Object
- ESI::Tag::Include::Request
- Defined in:
- lib/esi/tag/include.rb
Overview
ir = Request.new( ‘header1’=>‘value1’ )
ir.request( '/fragment' ) do|status,response|
if status
response.read_body do|str|
end
else
# error case
end
end
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#exception ⇒ Object
readonly
TODO.
-
#overflow_index ⇒ Object
readonly
TODO.
Instance Method Summary collapse
-
#initialize(forward_headers) ⇒ Request
constructor
A new instance of Request.
- #request(url, timeout = 1, alt_failover = nil, follow_limit = 3) ⇒ Object
Constructor Details
#initialize(forward_headers) ⇒ Request
Returns a new instance of Request.
33 34 35 |
# File 'lib/esi/tag/include.rb', line 33 def initialize(forward_headers) @headers = forward_headers end |
Instance Attribute Details
#exception ⇒ Object (readonly)
TODO
31 32 33 |
# File 'lib/esi/tag/include.rb', line 31 def exception @exception end |
#overflow_index ⇒ Object (readonly)
TODO
31 32 33 |
# File 'lib/esi/tag/include.rb', line 31 def overflow_index @overflow_index end |
Instance Method Details
#request(url, timeout = 1, alt_failover = nil, follow_limit = 3) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/esi/tag/include.rb', line 37 def request(url, timeout = 1, alt_failover=nil, follow_limit=3) uri = URI.parse(url) Net::HTTP.start(uri.host, uri.port) do|http| http.read_timeout = timeout if timeout and timeout > 0 rp = uri.query ? "#{uri.path}?#{uri.query}" : uri.path http.request_get( rp, @headers ) do|response| case response when Net::HTTPSuccess yield true, response, url when Net::HTTPRedirection ir = Request.new(@headers) ir.request(response['location'], timeout, alt_failover, follow_limit - 1) do|s,r| yield s, r, response['location'] end else if alt_failover ir = Request.new(@headers) ir.request(alt_failover, timeout, nil, follow_limit) do|s,r| yield s, r, alt_failover end else yield false, Error.new("Failed to request fragment: #{uri.scheme}://#{uri.host}:#{uri.port}#{uri.path}", response), url end end end end rescue Timeout::Error => e yield false, Error.new("Failed to request fragment: #{uri.scheme}://#{uri.host}:#{uri.port}#{uri.path}, timeout error: #{e.}", nil), url end |