class HTTP::Response::Parser
Attributes
headers[R]
Public Class Methods
new()
click to toggle source
# File lib/http/response/parser.rb, line 8 def initialize @parser = HTTP::Parser.new(self) reset end
Public Instance Methods
add(data)
click to toggle source
# File lib/http/response/parser.rb, line 13 def add(data) @parser << data end
Also aliased as: <<
finished?()
click to toggle source
# File lib/http/response/parser.rb, line 72 def finished? @finished end
headers?()
click to toggle source
# File lib/http/response/parser.rb, line 18 def headers? !!@headers end
http_version()
click to toggle source
# File lib/http/response/parser.rb, line 22 def http_version @parser.http_version.join(".") end
on_body(chunk)
click to toggle source
# File lib/http/response/parser.rb, line 38 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 34 def on_headers_complete(headers) @headers = headers end
on_message_complete()
click to toggle source
# File lib/http/response/parser.rb, line 60 def on_message_complete @finished = true end
read(size)
click to toggle source
# File lib/http/response/parser.rb, line 46 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 64 def reset @parser.reset! @finished = false @headers = nil @chunk = nil end
status_code()
click to toggle source
# File lib/http/response/parser.rb, line 26 def status_code @parser.status_code end