rahulsmahadev commented on code in PR #18878:
URL: https://github.com/apache/iceberg/pull/18878#discussion_r4617244404


##########
core/src/main/java/org/apache/iceberg/rest/HTTPClient.java:
##########
@@ -169,6 +170,34 @@ public HTTPClient withAuthSession(AuthSession session) {
     return new HTTPClient(this, session);
   }
 
+  @VisibleForTesting
+  static String userAgent(String override, String prefix) {
+    if (override != null) {
+      checkVisibleAscii(REST_USER_AGENT, override);
+      return override;
+    }
+
+    // the format the REST spec recommends, with the library token after any 
caller tokens
+    String userAgent =
+        String.format(
+            "iceberg-java/%s (jvm %s)", IcebergBuild.version(), 
System.getProperty("java.version"));
+    if (prefix == null) {
+      return userAgent;
+    }
+
+    checkVisibleAscii(REST_USER_AGENT_PREFIX, prefix);
+    String tokens = prefix.strip();
+    return tokens.isEmpty() ? userAgent : tokens + " " + userAgent;
+  }
+
+  // the HTTP client silently replaces other characters with '?'
+  private static void checkVisibleAscii(String property, String value) {

Review Comment:
   Done.



##########
docs/docs/rest-catalog.md:
##########
@@ -90,7 +90,8 @@ at connection time through
 | `rest.client.connections-per-route` | `100`   | Maximum number of pooled 
connections per route.                                                          
                                                                                
                                                                                
                                           |
 | `rest.client.connection-timeout-ms` | null    | Timeout in milliseconds for 
establishing a connection to the server. If not set, the HTTP client library 
default is used.                                                                
                                                                                
                                           |
 | `rest.client.socket-timeout-ms`     | null    | Socket timeout in 
milliseconds for awaiting data on a connection. If not set, the HTTP client 
library default is used.                                                        
                                                                                
                                                      |
-| `rest.client.user-agent`            | null    | Custom `User-Agent` header 
value to send with each request. If not set, the HTTP client library default is 
used.                                                                           
                                                                                
                                         |
+| `rest.client.user-agent`            | null    | Replaces the whole 
`User-Agent` header. If unset, the header is `iceberg-java/<version> (jvm <java 
version>)`, after any tokens from `rest.client.user-agent.prefix`. Only visible 
ASCII characters and spaces are allowed.                                        
                                                 |
+| `rest.client.user-agent.prefix`     | null    | Client application's product 
tokens, such as `Trino/438`, sent before the `iceberg-java` token in the 
`User-Agent` header. Ignored if `rest.client.user-agent` is set. Only visible 
ASCII characters and spaces are allowed.                                        
                                                |

Review Comment:
   I'd keep the override winning. Integrations add their tokens through the 
prefix, and the follow-up for Spark, Flink and Kafka Connect does this. If 
setting both failed, each of them would have to check for 
`rest.client.user-agent` first, or users who set it would get an error. Letting 
the override win keeps a full value working as it did before this PR, and the 
docs for the prefix say it's ignored when `rest.client.user-agent` is set.



-- 
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