lib/microget.rb
def parse_status_and_headers(headers_str)
    status_and_headers = headers_str.split("\r\n")
    status_line = status_and_headers.shift
  
    # TODO: there is no support for repeating headers (like Cookie:)
    header_hash = status_and_headers.each_with_object({}) do | header, h|
      split_at = header.index(':')
      key, value = header[0...split_at], header[(split_at + 1)..-1]
      h[key] = value.strip
    end
    raise "Invalid response status line #{status_line}" unless status_line =~ STATUS_PAT
  
    http_version, status_code, status = $1, $2, $3
    [status_code.to_i, header_hash]
  end
# Parses a large string with CRLF separators within it into a neat Hash of header key=>values.
Parses a large string with CRLF separators within it into a neat Hash of header key=>values.
Parses a large string with CRLF separators within it into a neat Hash of header key = > values .
def parse_status_and_headers(headers_str)
    status_and_headers = headers_str.split("\r\n")
    status_line = status_and_headers.shift
    header_hash = status_and_headers.each_with_object({}) do | header, h|
      split_at = header.index(':')
      key, value = header[0...split_at], header[(split_at + 1)..-1]
      h[key] = value.strip
    end
    raise "Invalid response status line #{status_line}" unless status_line =~ STATUS_PAT
    http_version, status_code, status = $1, $2, $3
    [status_code.to_i, header_hash]
  end
def parse_status_and_headers ( headers_str ) status_and_headers = headers_str . split ( "\r\n" ) status_line = status_and_headers . shift header_hash = status_and_headers . each_with_object ( { } ) do | header , h | split_at = header . index ( ':' ) key , value = header [ 0 ... split_at ] , header [ ( split_at + 1 ) .. - 1 ] h [ key ] = value . strip end raise "Invalid response status line #{status_line}" unless status_line =~ STATUS_PAT http_version , status_code , status = $1 , $2 , $3 [ status_code . to_i , header_hash ] end
Parses a large string with CRLF separators within it into a neat Hash of header key=>values.
Parses a large string with CRLF separators within it into a neat Hash of header key = > values .
# TODO: there is no support for repeating headers (like Cookie:)
headers_str