class HTTPClient::Session

def parse_header(socket)

def parse_header(socket)
  timeout(@receive_timeout, ReceiveTimeoutError) do
    initial_line = nil
    begin
      begin
        initial_line = socket.gets("\n")
        if initial_line.nil?
          close
          raise KeepAliveDisconnected.new(self)
        end
      rescue Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EPIPE, IOError
        # JRuby can raise IOError instead of ECONNRESET for now
        close
        raise KeepAliveDisconnected.new(self, $!)
      end
      if StatusParseRegexp !~ initial_line
        @version = '0.9'
        @status = nil
        @reason = nil
        @next_connection = false
        @content_length = nil
        @readbuf = initial_line
        break
      end
      @version, @status, @reason = $1, $2.to_i, $3
      @next_connection = HTTP::Message.keep_alive_enabled?(@version)
      @headers = []
      while true
        line = socket.gets("\n")
        unless line
          raise BadResponseError.new('unexpected EOF')
        end
        line.chomp!
        break if line.empty?
        if line[0] == ?\  or line[0] == ?\t
          last = @headers.last[1]
          last << ' ' unless last.empty?
          last << line.strip
        else
          key, value = line.strip.split(/\s*:\s*/, 2)
          parse_content_header(key, value)
          @headers << [key, value]
        end
      end
    end while (@version == '1.1' && @status == 100)
  end
end