Class: Soren::Parsers::Response::Body
- Defined in:
- lib/soren/parsers/response/body.rb
Instance Method Summary collapse
-
#initialize(reader:, headers:, code:) ⇒ Body
constructor
: (reader: Soren::Socket::Reader, headers: Soren::Types::Response::Headers, code: Soren::Types::Response::Code) -> void.
-
#parse ⇒ Object
: -> String.
Constructor Details
#initialize(reader:, headers:, code:) ⇒ Body
: (reader: Soren::Socket::Reader, headers: Soren::Types::Response::Headers, code: Soren::Types::Response::Code) -> void
14 15 16 17 18 |
# File 'lib/soren/parsers/response/body.rb', line 14 def initialize(reader:, headers:, code:) @reader = reader #: Soren::Socket::Reader @headers = headers #: Soren::Types::Response::Headers @code = code #: Soren::Types::Response::Code end |
Instance Method Details
#parse ⇒ Object
: -> String
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/soren/parsers/response/body.rb', line 21 def parse return '' if no_body? raw_body = if @headers.chunked? parse_chunked_body else content_length = @headers.content_length if !content_length.nil? @reader.read_exactly(content_length) elsif @headers.keep_alive? raise Soren::Error::ProtocolError, 'cannot determine body length with keep-alive' else @reader.read_all end end decode_content_encodings(raw_body) end |