Class: HTTP::Response::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/http/response/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



6
7
8
9
# File 'lib/http/response/parser.rb', line 6

def initialize
  @parser = HTTP::Parser.new(self)
  reset
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



4
5
6
# File 'lib/http/response/parser.rb', line 4

def headers
  @headers
end

Instance Method Details

#add(data) ⇒ Object Also known as: <<



11
12
13
# File 'lib/http/response/parser.rb', line 11

def add(data)
  @parser << data
end

#chunkObject



44
45
46
47
# File 'lib/http/response/parser.rb', line 44

def chunk
  chunk, @chunk = @chunk, nil
  chunk
end

#finished?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/http/response/parser.rb', line 61

def finished?
  @finished
end

#headers?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/http/response/parser.rb', line 16

def headers?
  !!@headers
end

#http_versionObject



20
21
22
# File 'lib/http/response/parser.rb', line 20

def http_version
  @parser.http_version.join(".")
end

#on_body(chunk) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/http/response/parser.rb', line 36

def on_body(chunk)
  if @chunk
    @chunk << chunk
  else
    @chunk = chunk
  end
end

#on_headers_complete(headers) ⇒ Object

HTTP::Parser callbacks



32
33
34
# File 'lib/http/response/parser.rb', line 32

def on_headers_complete(headers)
  @headers = headers
end

#on_message_completeObject



49
50
51
# File 'lib/http/response/parser.rb', line 49

def on_message_complete
  @finished = true
end

#resetObject



53
54
55
56
57
58
59
# File 'lib/http/response/parser.rb', line 53

def reset
  @parser.reset!

  @finished = false
  @headers  = nil
  @chunk    = nil
end

#status_codeObject



24
25
26
# File 'lib/http/response/parser.rb', line 24

def status_code
  @parser.status_code
end