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


##########
core/src/main/java/org/apache/iceberg/rest/HTTPClient.java:
##########
@@ -169,6 +167,22 @@ public HTTPClient withAuthSession(AuthSession session) {
     return new HTTPClient(this, session);
   }
 
+  /**
+   * Returns the User-Agent recommended by the REST spec: the caller's product 
tokens, if any,
+   * followed by the iceberg-java token and the JVM version as a comment.
+   */
+  @VisibleForTesting
+  static String userAgent(String callerTokens) {
+    String userAgent =
+        String.format(
+            "iceberg-java/%s (jvm %s)", IcebergBuild.version(), 
System.getProperty("java.version"));
+    if (callerTokens == null || callerTokens.isBlank()) {
+      return userAgent;
+    }
+
+    return callerTokens.strip() + " " + userAgent;

Review Comment:
   The value goes into the header unchecked. I tried a range of values against 
httpclient5 5.6.5 over a raw socket. CR/LF is turned into spaces, so there is 
no header injection, but control characters and non-Latin-1 characters become 
`?`. Nothing is rejected, so a bad value silently produces garbage in server 
logs. Since the value is typically set by integrations, failing fast on 
anything outside visible ASCII plus space (0x20–0x7E) seems more useful than 
silently mangling it.



##########
docs/docs/rest-catalog.md:
##########
@@ -90,7 +90,7 @@ 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    | Client application's product 
tokens, such as `Trino/438`, sent before the `iceberg-java` token in the 
`User-Agent` header. If unset, the header is `iceberg-java/<version> (jvm <java 
version>)`.                                                                     
                                              |

Review Comment:
   Since #13234, `rest.client.user-agent` has been a full override of the 
header. With this PR, the same value is now treated as "caller tokens" and 
`iceberg-java/<version> (jvm …)` is appended. 
   
   That is the most straightforward approach, but is also a silent behavior 
change for existing users. For example, `rest.client.user-agent=MyApp/1.0` used 
to send exactly `MyApp/1.0` and would now send `MyApp/1.0 iceberg-java/1.11.0 
(jvm 17.0.9)`. 
   
   Most people won't mind, but anyone matching on the exact header (proxy 
rules, server-side filters, dashboards) would be affected.
   
   Would it be worth considering a separate property for the new behavior, for 
example `rest.client.user-agent.prefix`, and leaving `rest.client.user-agent` 
as a full override? That way:
   
   - existing configs keep working unchanged;
   - the new property's purpose is obvious from its name;
   - an escape hatch remains for deployments that need to control the whole 
header.



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