-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1948 from ClickHouse/v2_product_name
[client-v2] User-Agent
- Loading branch information
Showing
6 changed files
with
155 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
43 changes: 43 additions & 0 deletions
43
client-v2/src/main/java/com/clickhouse/client/api/internal/EnvUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.clickhouse.client.api.internal; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.net.InetAddress; | ||
import java.net.NetworkInterface; | ||
import java.util.Collections; | ||
|
||
/** | ||
* Environment utility class. | ||
*/ | ||
public class EnvUtils { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(EnvUtils.class); | ||
|
||
/** | ||
* Returns the local host name or IP address. Can be used to set {@code Referer} HTTP header. | ||
* If fails to find the local host name or address, returns an empty string. | ||
* @param returnAddress if true, return address; otherwise, return name | ||
* @return string representing the local host name or address | ||
*/ | ||
public static String getLocalhostNameOrAddress(final boolean returnAddress) { | ||
try { | ||
|
||
for (NetworkInterface networkInterface : Collections.list(NetworkInterface.getNetworkInterfaces())) { | ||
for (InetAddress inetAddress : Collections.list(networkInterface.getInetAddresses())) { | ||
if (inetAddress.isLoopbackAddress()) { | ||
continue; | ||
} | ||
if (returnAddress) { | ||
return inetAddress.getHostAddress(); | ||
} else { | ||
return inetAddress.getCanonicalHostName(); | ||
} | ||
} | ||
} | ||
} catch (Exception e) { | ||
LOG.error("Failed to get local host name or address", e); | ||
} | ||
return ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters