module Rev

Constants

VERSION

Public Instance Methods

parse_chunk_header() click to toggle source
# File lib/rev/http_client.rb, line 331
def parse_chunk_header
  return false unless parse_header(@chunk_header)

  @bytes_remaining = @chunk_header.chunk_size
  @chunk_header = HttpChunkHeader.new

  @state = @bytes_remaining > 0 ? :chunk_body : :response_footer      
  true
end
parse_header(header) click to toggle source
# File lib/rev/http_client.rb, line 290
def parse_header(header)
  return false if @data.empty?
  
  begin
    @parser_nbytes = @parser.execute(header, @data.to_str, @parser_nbytes)
  rescue Rev::HttpClientParserError
    on_error "invalid HTTP format, parsing fails"
    @state = :invalid
  end
  
  return false unless @parser.finished?

  # Clear parsed data from the buffer
  @data.read(@parser_nbytes)
  @parser.reset
  @parser_nbytes = 0
  
  true
end
parse_response_header() click to toggle source
# File lib/rev/http_client.rb, line 310
def parse_response_header
  return false unless parse_header(@response_header)

  unless @response_header.http_status and @response_header.http_reason
    on_error "no HTTP response"
    @state = :invalid
    return false
  end

  on_response_header(@response_header)

  if @response_header.chunked_encoding?
    @state = :chunk_header
  else
    @state = :body
    @bytes_remaining = @response_header.content_length
  end
  
  true
end
process_body() click to toggle source
# File lib/rev/http_client.rb, line 387
def process_body
  if @bytes_remaining.nil?
    on_body_data @data.read
    return false
  end
  
  if @bytes_remaining.zero?
    on_request_complete
    @state = :finished
    return false
  end

  if @data.size < @bytes_remaining
    @bytes_remaining -= @data.size
    on_body_data @data.read
    return false
  end

  on_body_data @data.read(@bytes_remaining)
  @bytes_remaining = 0

  if @data.empty?
    on_request_complete
    @state = :finished
  else
    on_error "garbage at end of body"
    @state = :invalid
  end

  false
end
process_chunk_body() click to toggle source
# File lib/rev/http_client.rb, line 341
def process_chunk_body
  if @data.size < @bytes_remaining
    @bytes_remaining -= @data.size
    on_body_data @data.read
    return false
  end

  on_body_data @data.read(@bytes_remaining)
  @bytes_remaining = 0
  
  @state = :chunk_footer      
  true
end

Public Class Methods

version() click to toggle source
# File lib/rev.rb, line 27
def self.version() VERSION end