Skip to content

Commit

Permalink
Change the logic of buildWebApplicationRootUrl to return a default …
Browse files Browse the repository at this point in the history
…result even for non web services.

PiperOrigin-RevId: 663912068
Change-Id: I5602d68b3bf3f60670e31a5f0179c611f75e9ad2
  • Loading branch information
tooryx authored and copybara-github committed Aug 16, 2024
1 parent 2f2bd0b commit 315dfe1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,12 @@ private static NetworkEndpoint buildUriNetworkEndPoint(URI uri) {
*/
public static String buildWebApplicationRootUrl(NetworkService networkService) {
checkNotNull(networkService);
checkArgument(isWebService(networkService));

if (!isWebService(networkService)) {
return "http://"
+ NetworkEndpointUtils.toUriAuthority(networkService.getNetworkEndpoint())
+ "/";
}

String rootUrl =
(isPlainHttp(networkService) ? "http://" : "https://")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,17 @@ public void buildWebApplicationRootUrl_whenHttpsServiceOnPort443_removesTrailing
.isEqualTo("https://127.0.0.1/test_root/");
}

@Test
public void buildWebApplicationRootUrl_whenNotWebService_returnsHttpUrl() {
assertThat(
NetworkServiceUtils.buildWebApplicationRootUrl(
NetworkService.newBuilder()
.setNetworkEndpoint(forIpAndPort("127.0.0.1", 2121))
.setServiceName("unknown")
.build()))
.isEqualTo("http://127.0.0.1:2121/");
}

@Test
public void buildUriNetworkService_returnsNetworkService() throws IOException {

Expand Down

0 comments on commit 315dfe1

Please sign in to comment.