arturobernalg commented on code in PR #436:
URL: 
https://github.com/apache/httpcomponents-client/pull/436#discussion_r1174603179


##########
httpclient5/src/main/java/org/apache/hc/client5/http/auth/NTCredentials.java:
##########
@@ -192,15 +217,27 @@ private static String stripDotSuffix(final String value) {
         return value;
     }
 
-    /** Convert host to standard form */
-    private static String convertHost(final String host) {
-        return stripDotSuffix(host);
-    }
-
     /** Convert domain to standard form */
     private static String convertDomain(final String domain) {
         final String returnString = stripDotSuffix(domain);
         return returnString == null ? returnString : 
returnString.toUpperCase(Locale.ROOT);
     }
 
+
+    /**
+     * Retrieves the workstation name of the computer originating the request.
+     * This method attempts to get the local host name using the InetAddress 
class.
+     * If it fails to retrieve the host name due to an UnknownHostException, 
it returns "localhost" as a fallback.
+     *
+     * @return The workstation name as a String.
+     */
+    private static String getWorkstationName() {
+        try {
+            final InetAddress addr = InetAddress.getLocalHost();
+            return addr.getHostName();

Review Comment:
   It is not guaranteed that InetAddress.getLocalHost().getHostName() will 
consistently return the unqualified name (i.e., the local part without the 
domain name). The behavior of this method can vary depending on the system 
configuration, and in some cases, it may return the fully qualified domain name 
(FQDN).
   
   An alternative approach involves using 
NetworkInterface.getNetworkInterfaces(), but this can potentially be more 
resource-intensive, which might not be ideal. However, for most use cases, 
relying on InetAddress.getLocalHost().getHostName() should be sufficient to 
obtain the unqualified hostname.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org

Reply via email to