class HTTP::Response::Parser

Attributes

headers[R]

Public Class Methods

new() click to toggle source
# File lib/http/response/parser.rb, line 7
def initialize
  @parser = HTTP::Parser.new(self)
  reset
end

Public Instance Methods

<<(data)
Alias for: add
add(data) click to toggle source
# File lib/http/response/parser.rb, line 12
def add(data)
  @parser << data
end
Also aliased as: <<
finished?() click to toggle source
# File lib/http/response/parser.rb, line 71
def finished?
  @finished
end
headers?() click to toggle source
# File lib/http/response/parser.rb, line 17
def headers?
  !!@headers
end
http_version() click to toggle source
# File lib/http/response/parser.rb, line 21
def http_version
  @parser.http_version.join(".")
end
on_body(chunk) click to toggle source
# File lib/http/response/parser.rb, line 37
def on_body(chunk)
  if @chunk
    @chunk << chunk
  else
    @chunk = chunk
  end
end
on_headers_complete(headers) click to toggle source

HTTP::Parser callbacks

# File lib/http/response/parser.rb, line 33
def on_headers_complete(headers)
  @headers = headers
end
on_message_complete() click to toggle source
# File lib/http/response/parser.rb, line 59
def on_message_complete
  @finished = true
end
read(size) click to toggle source
# File lib/http/response/parser.rb, line 45
def read(size)
  return if @chunk.nil?

  if @chunk.bytesize <= size
    chunk  = @chunk
    @chunk = nil
  else
    chunk = @chunk.byteslice(0, size)
    @chunk[0, size] = ""
  end

  chunk
end
reset() click to toggle source
# File lib/http/response/parser.rb, line 63
def reset
  @parser.reset!

  @finished = false
  @headers  = nil
  @chunk    = nil
end
status_code() click to toggle source
# File lib/http/response/parser.rb, line 25
def status_code
  @parser.status_code
end