function getCrossOriginUrlWithRedirects(testserverUrl, redirectIfRange) {
  const url = new URL(testserverUrl);
  if (!isNodeJS) {
    // The responses are going to be cross-origin. In Node.js, fetch() allows
    // cross-origin requests for any request, but in browser environments we
    // need to enable CORS.
    // This option depends on crossOriginHandler in webserver.mjs.
    url.searchParams.set("cors", "withoutCredentials");
  }

  // This redirect options depend on redirectHandler in webserver.mjs.

  // We will change the host to a cross-origin domain so that the initial
  // request will be cross-origin. Set "redirectToHost" to the original host
  // to force a cross-origin redirect (relative to the initial URL).
  url.searchParams.set("redirectToHost", url.hostname);
  url.hostname = getCrossOriginHostname(url.hostname);
  if (redirectIfRange) {
    url.searchParams.set("redirectIfRange", "1");
  }
  return url.href;
}
@param {string} testserverUrl - A URL handled that supports CORS and
  redirects (see crossOriginHandler and redirectHandler in webserver.mjs).
@param {boolean} redirectIfRange - Whether Range requests should be
  redirected to a different origin compared to the initial request.
@returns {string} A URL that will be redirected by the server.