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.



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

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

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



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

def headers
  @headers
end

Instance Method Details

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



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

def add(data)
  @parser << data
end

#chunkObject



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

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

#finished?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/http/response/parser.rb', line 63

def finished?
  @finished
end

#headers?Boolean

Returns:

  • (Boolean)


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

def headers?
  !!@headers
end

#http_versionObject



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

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

#on_body(chunk) ⇒ Object



37
38
39
40
41
42
43
# 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) ⇒ Object

HTTP::Parser callbacks



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

def on_headers_complete(headers)
  @headers = headers
end

#on_message_completeObject



51
52
53
# File 'lib/http/response/parser.rb', line 51

def on_message_complete
  @finished = true
end

#resetObject



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

def reset
  @parser.reset!

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

#status_codeObject



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

def status_code
  @parser.status_code
end