Skip to content

Commit

Permalink
keep original request body when the request is mocked and diff_mode i…
Browse files Browse the repository at this point in the history
…s enabled
  • Loading branch information
yangfan100 committed Nov 6, 2023
1 parent c37d86d commit 40a212a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lyrebird/mock/handlers/handler_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __init__(self, request):
self.is_proxiable = True
self.response_chunk_size = 2048
self._parse_request()
self.request_raw_data = None

def _parse_request(self):
# Read stream
Expand Down Expand Up @@ -187,7 +188,9 @@ def get_request_body(self, in_request_handler=True):

_data = DataHelper.flow2origin(self.flow['request'], chain=self.request_chain)
else:
if in_request_handler:
if self.request_raw_data:
_data = self.request_raw_data
elif in_request_handler:
_data = self.request.data or self.request.form or None
else:
_data = DataHelper.flow2origin(self.flow['request'])
Expand Down
3 changes: 3 additions & 0 deletions lyrebird/mock/handlers/mock_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,6 @@ def handle(self, handler_context):
'mock_id': hit_data['id']
})
MockDataHelper.read_mock_data(handler_context)
# Keep the original request body and use it in diff_mode
if context.application.is_diff_mode == context.MockMode.MULTIPLE and handler_context.response_source == 'mock':
handler_context.request_raw_data = handler_context.request.data
2 changes: 1 addition & 1 deletion lyrebird/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
IVERSION = (2, 21, 0)
IVERSION = (2, 21, 1)
VERSION = ".".join(str(i) for i in IVERSION)
LYREBIRD = "Lyrebird " + VERSION

0 comments on commit 40a212a

Please sign in to comment.