jianghuazhu commented on code in PR #4659:
URL: https://github.com/apache/hadoop/pull/4659#discussion_r939508358


##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/CallerContext.java:
##########
@@ -121,6 +122,51 @@ public String toString() {
     return str;
   }
 
+  /**
+   * Try to obtain the value corresponding to the key by parsing the content.
+   * @param content the full content to be parsed.
+   * @param key trying to obtain the value of the key.
+   * @return the value corresponding to the key.
+   */
+  @VisibleForTesting
+  public static String parseSpecialValue(String content, String key) {
+    int posn = content.indexOf(key);
+    if (posn != -1) {
+      posn += key.length();
+      int end = content.indexOf(",", posn);
+      return end == -1 ? content.substring(posn) : content.substring(posn, 
end);
+    }
+    return null;
+  }
+
+  /**
+   * Get client ip content from caller context.
+   * @param context The context here is obtained from outside.
+   * @return Filter the value carried by 'clientIp:' from the context.
+   *         If not, return null.
+   */
+  public static String getRealClientIp(String context) {
+    if (context != null && !context.equals("")) {

Review Comment:
   The string here is obtained from outside.



##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/CallerContext.java:
##########
@@ -121,6 +122,51 @@ public String toString() {
     return str;
   }
 
+  /**
+   * Try to obtain the value corresponding to the key by parsing the content.
+   * @param content the full content to be parsed.
+   * @param key trying to obtain the value of the key.
+   * @return the value corresponding to the key.
+   */
+  @VisibleForTesting
+  public static String parseSpecialValue(String content, String key) {
+    int posn = content.indexOf(key);
+    if (posn != -1) {
+      posn += key.length();
+      int end = content.indexOf(",", posn);
+      return end == -1 ? content.substring(posn) : content.substring(posn, 
end);
+    }
+    return null;
+  }
+
+  /**
+   * Get client ip content from caller context.
+   * @param context The context here is obtained from outside.
+   * @return Filter the value carried by 'clientIp:' from the context.
+   *         If not, return null.
+   */
+  public static String getRealClientIp(String context) {
+    if (context != null && !context.equals("")) {
+      String ipKey = CLIENT_IP_STR + Builder.KEY_VALUE_SEPARATOR;
+      return parseSpecialValue(context, ipKey);
+    }
+    return null;
+  }
+
+  /**
+   * Get client port content from caller context.
+   * @param context The context here is obtained from outside.
+   * @return Filter the value carried by 'clientPort:' from the context.
+   *         If not, return null.
+   */
+  public static String getRealClientPort(String context) {
+    if (context != null && !context.equals("")) {

Review Comment:
   The string here is obtained from outside.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to