Return binary response data
(har_response)
| 31 | |
| 32 | |
| 33 | def get_response_body_bytes(har_response): |
| 34 | """ Return binary response data """ |
| 35 | content = har_response['content'] |
| 36 | body = content.get('text', None) |
| 37 | if body is None: |
| 38 | return None |
| 39 | encoding = content.get('encoding', None) |
| 40 | if encoding == 'base64': |
| 41 | return base64.b64decode(body) |
| 42 | if encoding is None or encoding == 'binary': |
| 43 | if not isinstance(body, bytes): |
| 44 | return body.encode('utf8') |
| 45 | return body |
| 46 | else: |
| 47 | raise ValueError("Unsupported HAR content encoding: %r" % encoding) |