<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _update_response_location_header(self, resource):
 """ Adds a new or replaces an existing Location header to the response headers pointing to the URL of the given resource. """

        location = resource_to_url(resource, request=self.request)
        loc_hdr = ('Location', location)
        hdr_names = [hdr[0].upper() for hdr in self.request.response.headerlist]
        try:
            idx = hdr_names.index('LOCATION')
        except ValueError:
            self.request.response.headerlist.append(loc_hdr)
        else:
            # Replace existing location header.
            # FIXME: It is not clear under which conditions this happens, so
            #        we do not have a test for it yet.
            self.request.response.headerlist[idx] = loc_hdr