<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def collect_metrics_for_response(http_response, context, trace, http_filter):
 """ Collects relevant metrics from a requests Response object and adds them to the IOpipe context. """

    http_response = copy.deepcopy(http_response)
    if http_filter is not None and callable(http_filter):
        http_response = http_filter(http_response)
        if http_response is False:
            return

    request = None
    if hasattr(http_response, "request"):
        parsed_url = None
        if hasattr(http_response.request, "url"):
            parsed_url = urlparse(http_response.request.url)

        request_headers = []
        if hasattr(http_response.request, "headers"):
            request_headers = [
                {"key": ensure_utf8(k), "string": ensure_utf8(v)}
                for k, v in http_response.request.headers.items()
                if k.lower() in INCLUDE_HEADERS
            ]

        request = Request(
            hash=ensure_utf8(getattr(parsed_url, "fragment", None)),
            headers=request_headers,
            hostname=ensure_utf8(getattr(parsed_url, "hostname", None)),
            method=ensure_utf8(getattr(http_response.request, "method", None)),
            path=ensure_utf8(getattr(parsed_url, "path", None)),
            # TODO: Determine if this is redundant
            pathname=ensure_utf8(getattr(parsed_url, "path", None)),
            port=ensure_utf8(getattr(parsed_url, "port", None)),
            protocol=ensure_utf8(getattr(parsed_url, "scheme", None)),
            query=ensure_utf8(getattr(parsed_url, "query", None)),
            url=ensure_utf8(getattr(http_response.request, "url", None)),
        )

    response_headers = []
    if hasattr(http_response, "headers"):
        response_headers = [
            {"key": ensure_utf8(k), "string": ensure_utf8(v)}
            for k, v in http_response.headers.items()
            if k.lower() in INCLUDE_HEADERS
        ]

    response = Response(
        headers=response_headers,
        statusCode=ensure_utf8(getattr(http_response, "status_code", None)),
        statusMessage=None,
    )

    context.iopipe.mark.http_trace(trace, request, response)