class Google::Apis::Core::CallDeserializer
Deconstructs a raw HTTP response part @private
Public Instance Methods
to_http_response(call_response)
click to toggle source
Parse a batched response.
@param [String] call_response
the response to parse.
@return [Array<(Fixnum, Hash, String)>]
Status, header, and response body.
# File lib/google/apis/core/batch.rb, line 203 def to_http_response(call_response) outer_header, outer_body = split_header_and_body(call_response) status_line, payload = outer_body.split(/\n/, 2) _, status = status_line.split(' ', 3) header, body = split_header_and_body(payload) [outer_header, status.to_i, header, body] end
Protected Instance Methods
split_header_and_body(response)
click to toggle source
Auxiliary method to split the header from the body in an HTTP response.
@param [String] response
the response to parse.
@return [Array<(HTTP::Message::Headers, String)>]
the header and the body, separately.
# File lib/google/apis/core/batch.rb, line 220 def split_header_and_body(response) header = HTTP::Message::Headers.new payload = response.lstrip while payload line, payload = payload.split(/\n/, 2) line.sub!(/\s+\z/, '') break if line.empty? match = /\A([^:]+):\s*/.match(line) fail BatchError, sprintf('Invalid header line in response: %s', line) if match.nil? header[match[1]] = match.post_match end [header, payload] end