From ce888f5b5eb96abd5d575f272f11087bef4cd068 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sat, 28 Apr 2018 15:43:01 +0200 Subject: Fetch request POST body If there is any and it was not included in the response already. --- crocoite/browser.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'crocoite/browser.py') diff --git a/crocoite/browser.py b/crocoite/browser.py index 0840374..efe739a 100644 --- a/crocoite/browser.py +++ b/crocoite/browser.py @@ -82,7 +82,21 @@ class Item: rawBody = rawBody.encode ('utf8') return rawBody, base64Encoded except (pychrome.exceptions.CallMethodException, pychrome.exceptions.TimeoutException): - return None, False + raise ValueError ('Cannot fetch response body') + + @property + def requestBody (self): + """ Get request/POST body """ + req = self.request + postData = req.get ('postData') + if postData: + return postData.encode ('utf8'), False + elif req.get ('hasPostData', False): + try: + return b64decode (self.tab.Network.getRequestPostData (requestId=self.id, _timeout=60)['postData']), True + except (pychrome.exceptions.CallMethodException, pychrome.exceptions.TimeoutException): + raise ValueError ('Cannot fetch request body') + return None, False def setRequest (self, req): self.chromeRequest = req -- cgit v1.2.3