Class: HTTP::Response::Parser
- Inherits:
-
Object
- Object
- HTTP::Response::Parser
- Defined in:
- lib/http/response/parser.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Instance Method Summary collapse
- #add(data) ⇒ Object (also: #<<)
- #finished? ⇒ Boolean
- #headers? ⇒ Boolean
- #http_version ⇒ Object
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
- #on_body(chunk) ⇒ Object
-
#on_headers_complete(headers) ⇒ Object
HTTP::Parser callbacks.
- #on_message_complete ⇒ Object
- #read(size) ⇒ Object
- #reset ⇒ Object
- #status_code ⇒ Object
Constructor Details
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
6 7 8 |
# File 'lib/http/response/parser.rb', line 6 def headers @headers end |
Instance Method Details
#add(data) ⇒ Object Also known as: <<
13 14 15 |
# File 'lib/http/response/parser.rb', line 13 def add(data) @parser << data end |
#finished? ⇒ Boolean
72 73 74 |
# File 'lib/http/response/parser.rb', line 72 def finished? @finished end |
#headers? ⇒ Boolean
18 19 20 |
# File 'lib/http/response/parser.rb', line 18 def headers? !!@headers end |
#http_version ⇒ Object
22 23 24 |
# File 'lib/http/response/parser.rb', line 22 def http_version @parser.http_version.join(".") end |
#on_body(chunk) ⇒ Object
38 39 40 41 42 43 44 |
# 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) ⇒ Object
HTTP::Parser callbacks
34 35 36 |
# File 'lib/http/response/parser.rb', line 34 def on_headers_complete(headers) @headers = headers end |
#on_message_complete ⇒ Object
60 61 62 |
# File 'lib/http/response/parser.rb', line 60 def @finished = true end |
#read(size) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/http/response/parser.rb', line 64 def reset @parser.reset! @finished = false @headers = nil @chunk = nil end |
#status_code ⇒ Object
26 27 28 |
# File 'lib/http/response/parser.rb', line 26 def status_code @parser.status_code end |