예제 #1
0
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,
    }
예제 #2
0
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,
    }