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.
103 104 105 |
# File 'lib/http/response/parser.rb', line 103 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.
66 67 68 69 70 71 72 |
# File 'lib/http/response/parser.rb', line 66 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 54 |
# File 'lib/http/response/parser.rb', line 51 def on_header_field(_response, field) append_header if @reading_header_value @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.
56 57 58 59 |
# File 'lib/http/response/parser.rb', line 56 def on_header_value(_response, value) @reading_header_value = true @field_value << value 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.
61 62 63 64 |
# File 'lib/http/response/parser.rb', line 61 def on_headers_complete(_reposse) append_header if @reading_header_value @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.
88 89 90 |
# File 'lib/http/response/parser.rb', line 88 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.
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/http/response/parser.rb', line 74 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.
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/http/response/parser.rb', line 92 def reset @state.reset! @finished = Hash.new(false) @headers = HTTP::Headers.new @reading_header_value = false @field = +"" @field_value = +"" @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 |