Exemple #1
0
    def update_client_resp_time(self):
        self.client_resp_time = time.time()
        # 消息总线 客户端响应事件,启用此事件
        resp_data = self.flow['response'].get('data', '')
        if isinstance(resp_data, str):
            self.flow['size'] = len(resp_data.encode())
        else:
            self.flow['size'] = len(resp_data)

        self.flow['duration'] = self.server_resp_time - self.client_req_time

        method = self.flow['request']['method']
        url = self.flow['request']['url']
        code = self.flow['response']['code']
        duration = utils.convert_time(self.flow['duration'])
        size = utils.convert_size(self.flow['size'])
        context.application.event_bus.publish(
            'flow',
            dict(
                flow=self.flow,
                message=
                f"URL: {url}\nMethod: {method}\nStatusCode: {code}\nDuration: {duration}\nSize: {size}"
            ))

        if context.application.work_mode == context.Mode.RECORD:
            dm = context.application.data_manager
            dm.save_data(self.flow)
Exemple #2
0
 def update_client_resp_time(self):
     self.client_resp_time = time.time()
     # 消息总线 客户端响应事件, 目前仅启用此事件
     method = self.flow['request']['method']
     url = self.flow['request']['url']
     code = self.flow['response']['code']
     duration = utils.convert_time(self.flow['duration'])
     size = utils.convert_size(self.flow['size'])
     context.application.event_bus.publish('flow',
     dict(
         flow=self.flow,
         message=f"URL: {url}\nMethod: {method}\nStatusCode: {code}\nDuration: {duration}\nSize: {size}"
         )
     )