Class: ESI::Processor
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#router ⇒ Object
readonly
Returns the value of attribute router.
Instance Method Summary collapse
-
#initialize(config, router, cache_buffer = nil) ⇒ Processor
constructor
A new instance of Processor.
- #send_body(http_request, params, http_response, proxy_response) ⇒ Object
- #send_chunk ⇒ Object
Methods included from Log
#log, #log_debug, #log_error, #log_request, #msg
Constructor Details
#initialize(config, router, cache_buffer = nil) ⇒ Processor
Returns a new instance of Processor.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/esi/processor.rb', line 11 def initialize( config, router, cache_buffer = nil ) @config = config @router = router @chunk_count = 0 @chunk_size = @config[:chunk_size] || 4096 @bytes_sent = 0 @max_depth = @config[:max_depth] || 3 @chunk_buffer = StringIO.new # when buffer reaches chunk_size write to the http_response socket @parser = ESI::Parser.new( @chunk_buffer, @router, @config.cache, @max_depth ) @cache_buffer = cache_buffer end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
7 8 9 |
# File 'lib/esi/processor.rb', line 7 def config @config end |
#router ⇒ Object (readonly)
Returns the value of attribute router.
7 8 9 |
# File 'lib/esi/processor.rb', line 7 def router @router end |
Instance Method Details
#send_body(http_request, params, http_response, proxy_response) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/esi/processor.rb', line 23 def send_body( http_request, params, http_response, proxy_response ) @http_response = http_response # prepare the parser given the raw request params and the preprocessed request params @parser.prepare( http_request.params, params ) # feed data to the parser proxy_response.read_body do |data| @parser.process data @cache_buffer << data if @cache_buffer if @chunk_buffer.size > @chunk_size send_chunk @chunk_buffer = StringIO.new @parser.response.update_output( @chunk_buffer ) end end @parser.finish send_chunk [@chunk_count,@bytes_sent] rescue => e STDERR.puts "\n#{e.}: #{e.backtrace.join("\n")}\n" ensure http_response.write( "0\r\n\r\n" ) http_response.done = true if http_response.respond_to?(:done) end |
#send_chunk ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/esi/processor.rb', line 53 def send_chunk @chunk_buffer.rewind size = @chunk_buffer.size chunk_header = "#{"%x" % size}" + Mongrel::Const::LINE_END #print chunk_header @http_response.write( chunk_header ) # write the chunk size @http_response.write( @chunk_buffer.read + Mongrel::Const::LINE_END ) # write the chunk @bytes_sent += size @chunk_count += 1 end |