Class: HTTP::Response::Parser Private
- Inherits:
-
Object
- Object
- HTTP::Response::Parser
- Defined in:
- lib/http/response/parser.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
NOTE(ixti): This class is a subject of future refactoring, thus don't expect this class API to be stable until this message disappears and class is not marked as private anymore.
Instance Attribute Summary collapse
- #headers ⇒ Object readonly private
Instance Method Summary collapse
- #add(data) ⇒ self (also: #<<) private
- #finished? ⇒ Boolean private
- #headers? ⇒ Boolean private
- #http_version ⇒ Object private
-
#initialize ⇒ Parser
constructor
private
A new instance of Parser.
- #on_body(_response, chunk) ⇒ Object private
-
#on_header_field(_response, field) ⇒ Object
private
HTTP::Parser callbacks.
- #on_header_value(_response, value) ⇒ Object private
- #on_headers_complete(_reposse) ⇒ Object private
- #on_message_complete(_response) ⇒ Object private
- #read(size) ⇒ Object private
- #reset ⇒ Object private
- #status_code ⇒ Object private
Constructor Details
#initialize ⇒ Parser
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Parser.
15 16 17 18 19 20 |
# File 'lib/http/response/parser.rb', line 15 def initialize @state = HttpParser::Parser.new_instance { |i| i.type = :response } @parser = HttpParser::Parser.new(self) reset end |
Instance Attribute Details
#headers ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
13 14 15 |
# File 'lib/http/response/parser.rb', line 13 def headers @headers end |
Instance Method Details
#add(data) ⇒ self Also known as: <<
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/http/response/parser.rb', line 23 def add(data) # XXX(ixti): API doc of HttpParser::Parser is misleading, it says that # it returns boolean true if data was parsed successfully, but instead # it's response tells if there was an error; So when it's `true` that # means parse failed, and `false` means parse was successful. # case of success. return self unless @parser.parse(@state, data) raise IOError, "Could not parse data" end |
#finished? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
98 99 100 |
# File 'lib/http/response/parser.rb', line 98 def finished? @finished[:message] end |
#headers? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
35 36 37 |
# File 'lib/http/response/parser.rb', line 35 def headers? @finished[:headers] end |
#http_version ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
39 40 41 |
# File 'lib/http/response/parser.rb', line 39 def http_version @state.http_version end |
#on_body(_response, chunk) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
63 64 65 66 67 68 69 |
# File 'lib/http/response/parser.rb', line 63 def on_body(_response, chunk) if @chunk @chunk << chunk else @chunk = chunk end end |
#on_header_field(_response, field) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
HTTP::Parser callbacks
51 52 53 |
# File 'lib/http/response/parser.rb', line 51 def on_header_field(_response, field) @field = field end |
#on_header_value(_response, value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
55 56 57 |
# File 'lib/http/response/parser.rb', line 55 def on_header_value(_response, value) @headers.add(@field, value) if @field end |
#on_headers_complete(_reposse) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
59 60 61 |
# File 'lib/http/response/parser.rb', line 59 def on_headers_complete(_reposse) @finished[:headers] = true end |
#on_message_complete(_response) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
85 86 87 |
# File 'lib/http/response/parser.rb', line 85 def (_response) @finished[:message] = true end |
#read(size) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/http/response/parser.rb', line 71 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
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
89 90 91 92 93 94 95 96 |
# File 'lib/http/response/parser.rb', line 89 def reset @state.reset! @finished = Hash.new(false) @headers = HTTP::Headers.new @field = nil @chunk = nil end |
#status_code ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
43 44 45 |
# File 'lib/http/response/parser.rb', line 43 def status_code @state.http_status end |