Return a response that is conditional to a given request.

        Returns the Response object unchanged, or a new Response object
        with a "304 Not Modified" status code.

def conditional_to(self, request):
        """Return a response that is conditional to a given request.

        Returns the Response object unchanged, or a new Response object
        with a "304 Not Modified" status code.
        """
        if not self.code == 200:
            return self

        request_headers = request.headers
        response_headers = self.headers

        if_none_match = request_headers.get('If-None-Match')
        if_modified_since = request_headers.get('If-Modified-Since')

        etag_ok, date_ok = False, False

        if if_none_match:
            etag = response_headers.get('ETag')
            if etag and match_etag(etag, if_none_match, weak=True):
                etag_ok = True

        if if_modified_since:
            last_modified = response_headers.get('Last-Modified')
            if last_modified:
                try:
                    modified_ts = httpdate_to_timestamp(last_modified)
                    last_valid_ts = httpdate_to_timestamp(if_modified_since)
                    if modified_ts <= last_valid_ts:
                        date_ok = True
                except:
                    pass  # Ignore invalid dates

        if if_none_match and not etag_ok:
            return self
        elif if_modified_since and not date_ok:
            return self
        elif etag_ok or date_ok:
            headers = filter_304_headers(self.headers.items())
            if 'Date' not in self.headers:
                headers.append(('Date', datetime_to_httpdate(time.time())))
            return Response(status=304, headers=headers, body='')
        return self