From 57f55fefb386b231538a05a92b92acefb5598c96 Mon Sep 17 00:00:00 2001 From: noO0ob Date: Fri, 20 Dec 2024 10:41:55 +0800 Subject: [PATCH 1/2] fix post process error when response data is empty --- lyrebird/mock/handlers/flow_editor_handler.py | 2 -- lyrebird/mock/handlers/handler_context.py | 4 +++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lyrebird/mock/handlers/flow_editor_handler.py b/lyrebird/mock/handlers/flow_editor_handler.py index 99d3f237..a193d561 100644 --- a/lyrebird/mock/handlers/flow_editor_handler.py +++ b/lyrebird/mock/handlers/flow_editor_handler.py @@ -53,8 +53,6 @@ def on_response_handler(self, handler_context): if not handler_context.flow['response'].get('data'): if handler_context.response: handler_context.update_response_data2flow() - else: - handler_context.flow['response']['data'] = None self.script_executor(matched_funcs, handler_context.flow) handler_context.set_response_edited() diff --git a/lyrebird/mock/handlers/handler_context.py b/lyrebird/mock/handlers/handler_context.py index 850e317e..3dcdcf78 100644 --- a/lyrebird/mock/handlers/handler_context.py +++ b/lyrebird/mock/handlers/handler_context.py @@ -309,8 +309,10 @@ def update_client_resp_time(self): resp_data = self.flow['response'].get('data', '') if isinstance(resp_data, str): self.flow['size'] = len(resp_data.encode()) - else: + elif resp_data: self.flow['size'] = len(resp_data) + else: + self.flow['size'] = 0 self.flow['duration'] = self.server_resp_time - self.client_req_time From 5a5f2dd7e0b43b4d2a33a8e2bc0ebe1510878cbe Mon Sep 17 00:00:00 2001 From: noO0ob Date: Fri, 20 Dec 2024 11:04:23 +0800 Subject: [PATCH 2/2] ensure data not exist --- lyrebird/mock/handlers/flow_editor_handler.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lyrebird/mock/handlers/flow_editor_handler.py b/lyrebird/mock/handlers/flow_editor_handler.py index a193d561..88b5c2f5 100644 --- a/lyrebird/mock/handlers/flow_editor_handler.py +++ b/lyrebird/mock/handlers/flow_editor_handler.py @@ -50,9 +50,11 @@ def on_response_handler(self, handler_context): handler_context.flow['response']['code'] = 200 if not handler_context.flow['response'].get('headers'): handler_context.flow['response']['headers'] = {} - if not handler_context.flow['response'].get('data'): + if 'data' not in handler_context.flow['response']: if handler_context.response: handler_context.update_response_data2flow() + else: + handler_context.flow['response']['data'] = None self.script_executor(matched_funcs, handler_context.flow) handler_context.set_response_edited()