Wrap returned http response into a well formatted dict
        :param kwargs: this dict param should contains following keys:
                           fd: file directory to
                           url: the test url fo the result
                           files_count: the number of files under har/ directory

        :return (dict): the results of all

def wrap_results(self, **kwargs):
        """
        Wrap returned http response into a well formatted dict
        :param kwargs: this dict param should contains following keys:
                           fd: file directory to
                           url: the test url fo the result
                           files_count: the number of files under har/ directory

        :return (dict): the results of all
        """

        if 'fd' not in kwargs \
                or 'url' not in kwargs \
                or 'files_count' not in kwargs:
            logging.error("Missing arguments in wrap_results function")
            return {}

        external = kwargs['external'] if 'external' in kwargs else None
        fd = kwargs['fd']
        url = kwargs['url']
        length = kwargs['files_count']

        results = {}

        files = []
        wait_time = 15
        host = self.divide_url(url)[0]
        time.sleep(0.5)

        # wait until the har file is generated
        while len(os.listdir(fd)) <= length + self.parsed:
            time.sleep(1)
            wait_time -= 1
            if wait_time == 0:
                logging.warning("%s waiting har file result timed out" % url)
                results['error'] = "wrap har file timeout"
                if external is not None:
                    external[url] = results
                return results
        time.sleep(1)

        # find all har files under har/ directory
        for fn in os.listdir(fd):
            if fn.endswith(".har") and host in fn:
                path = os.path.join(fd, fn)
                files.append((fn, os.stat(path).st_mtime))

        # sort all har files and parse the latest one
        files.sort(key=lambda x: x[1])
        if len(files) > 0:
            with open(fd + '/' + files[-1][0]) as f:
                raw_data = json.load(f)['log']['entries']
                results = [{} for i in range(0, len(raw_data))]
                for i in range(0, len(results)):

                    results[i]['request'] = {}
                    results[i]['request']['method'] = raw_data[i]['request']['method']
                    headers = {}
                    for header in raw_data[i]['request']['headers']:
                        headers[header['name']] = header['value']
                    results[i]['request']['headers'] = headers

                    results[i]['response'] = {}
                    results[i]['response']['status'] = raw_data[i]['response']['status']
                    results[i]['response']['reason'] = raw_data[i]['response']['statusText']
                    headers = {}
                    for header in raw_data[i]['response']['headers']:
                        headers[header['name']] = header['value']
                    results[i]['response']['headers'] = headers
                    results[i]['response']['redirect'] = raw_data[i]['response']['redirectURL']
                    results[i]['response']['body'] = raw_data[i]['response']['content']

            self.parsed += 1  # increment the number of parsed har files
        else:
            logging.warning("Cannot find har file for %s" % url)

        # save test result of this url to the external result object or 
        # return the result
        if external is not None:
            external[url] = results
        else:
            return results