def serialize_prepared_request(request, method): headers = request.headers return { 'body': request.body or '', 'headers': dict( (coerce_content(k, 'utf-8'), v) for (k, v) in headers.items() ), 'method': request.method, 'uri': request.url, }
def serialize_response(response, method): body = {'encoding': response.encoding} if response.headers.get('Content-Encoding') == 'gzip': body['base64_string'] = base64.b64encode(response.raw.read()).decode() else: body['string'] = coerce_content(response.content, body['encoding']) return { 'body': body, 'headers': dict(response.headers), 'status_code': response.status_code, 'url': response.url, }