/** * Returns true if the canonicalized base URLs are equal and if the path of the {@code prefixUrl} is a prefix (in * the string sense) of the path of the given {@code fullUrl}. */ @VisibleForTesting static boolean isBaseUrlFor(HttpUrl baseUrl, HttpUrl fullUrl) { return fullUrl.scheme().equals(baseUrl.scheme()) && fullUrl.host().equals(baseUrl.host()) && fullUrl.port() == baseUrl.port() && isPathPrefixFor(baseUrl, fullUrl); }
/** * Returns true if the canonicalized base URLs are equal and if the path of the {@code prefixUrl} is a prefix (in * the string sense) of the path of the given {@code fullUrl}. */ @VisibleForTesting static boolean isBaseUrlFor(HttpUrl baseUrl, HttpUrl fullUrl) { return fullUrl.scheme().equals(baseUrl.scheme()) && fullUrl.host().equals(baseUrl.host()) && fullUrl.port() == baseUrl.port() && isPathPrefixFor(baseUrl, fullUrl); }
private Optional<HttpUrl> redirectTo(HttpUrl current, HttpUrl redirectBaseUrl) { Optional<Integer> baseUrlIndex = indexFor(redirectBaseUrl); baseUrlIndex.ifPresent(currentUrl::set); return baseUrlIndex .map(baseUrls::get) .flatMap(baseUrl -> { if (!isPathPrefixFor(baseUrl, current)) { // The requested redirectBaseUrl has a path that is not compatible with // the path of the current URL return Optional.empty(); } else { return Optional.of(current.newBuilder() .scheme(baseUrl.scheme()) .host(baseUrl.host()) .port(baseUrl.port()) .encodedPath( baseUrl.encodedPath() // matching prefix + current.encodedPath().substring(baseUrl.encodedPath().length())) .build()); } }); }
private Optional<HttpUrl> redirectTo(HttpUrl current, HttpUrl redirectBaseUrl) { Optional<Integer> baseUrlIndex = indexFor(redirectBaseUrl); baseUrlIndex.ifPresent(currentUrl::set); return baseUrlIndex .map(baseUrls::get) .flatMap(baseUrl -> { if (!isPathPrefixFor(baseUrl, current)) { // The requested redirectBaseUrl has a path that is not compatible with // the path of the current URL return Optional.empty(); } else { return Optional.of(current.newBuilder() .scheme(baseUrl.scheme()) .host(baseUrl.host()) .port(baseUrl.port()) .encodedPath( baseUrl.encodedPath() // matching prefix + current.encodedPath().substring(baseUrl.encodedPath().length())) .build()); } }); }