def generate_canonical_request(method, parsed_url, headers, signed_headers,
    content_sha256):
    """
    Generate canonical request.

    :param method: HTTP method.
    :param parsed_url: Parsed url is input from :func:`urlsplit`
    :param headers: HTTP header dictionary.
    :param content_sha256: Content sha256 hexdigest string.
    """
    parsed_url_path = parsed_url.path.replace('%7E', '~')
    parsed_url_query = parsed_url.query.replace('%7E', '~')
    lines = [method, parsed_url_path, parsed_url_query]
    header_lines = []
    for header in signed_headers:
        value = headers[header.title()]
        value = str(value).strip()
        header_lines.append(header + ':' + value)
    lines = lines + header_lines
    lines.append('')
    lines.append(';'.join(signed_headers))
    lines.append(content_sha256)
    return '\n'.join(lines)
