DanielLeens commented on code in PR #13727:
URL: https://github.com/apache/seatunnel/pull/13727#discussion_r4731669405


##########
seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/client/HttpClientProvider.java:
##########
@@ -693,28 +645,58 @@ private void addHeaders(HttpRequestBase request, 
Map<String, String> headers) {
         headers.forEach(request::addHeader);
     }
 
-    private static boolean isFormContentType(Map<String, String> headers) {
+    private static Map<String, String> formHeaders(Map<String, String> 
headers) {
+        if (getContentType(headers) != null) {
+            return headers;
+        }
+        Map<String, String> result = headers == null ? new HashMap<>() : new 
HashMap<>(headers);
+        result.put(HTTP.CONTENT_TYPE, APPLICATION_FORM);
+        return result;
+    }
+
+    private static String getContentType(Map<String, String> headers) {
         if (MapUtils.isEmpty(headers)) {
-            return false;
+            return null;
         }
         return headers.entrySet().stream()
                 .filter(entry -> 
HTTP.CONTENT_TYPE.equalsIgnoreCase(entry.getKey()))
                 .map(Map.Entry::getValue)
                 .filter(Objects::nonNull)
-                .anyMatch(value -> 
APPLICATION_FORM.equalsIgnoreCase(value.trim()));
+                .findFirst()
+                .orElse(null);
+    }
+
+    private static boolean isFormContentType(String value) {
+        // Header elements expose the media type independently of charset and 
other parameters.
+        if (value == null) {
+            return false;
+        }
+        HeaderElement[] elements = new BasicHeader(HTTP.CONTENT_TYPE, 
value).getElements();
+        return elements.length > 0 && 
APPLICATION_FORM.equalsIgnoreCase(elements[0].getName());
+    }
+
+    private static boolean shouldParseFormBody(Map<String, String> headers, 
String body) {
+        String contentType = getContentType(headers);
+        if (!isFormContentType(contentType)) {
+            return false;
+        }
+        // Bare form headers historically accept HOCON. Parameterized headers 
also accept
+        // already encoded bodies verbatim, so only convert an explicit object 
on that path.
+        return APPLICATION_FORM.equalsIgnoreCase(contentType.trim()) || 
isObjectBody(body);

Review Comment:
   Thanks for catching this. I missed the charset-qualified compatibility 
distinction in my earlier assessment; that deserves a correction.
   
   At this head, HttpClientProvider.shouldParseFormBody:678-689 recognizes the 
form media type even with charset parameters and parses an object-shaped body. 
execute:149-159 uses HOCON entrySet, and addBody:692-713 stringifies the 
resulting values before form encoding. That is a different wire body from the 
earlier verbatim parameterized-header path; nested objects/lists should not be 
described as byte-for-byte compatible.
   
   I would preserve the established verbatim behavior for this nested 
parameterized-header case unless the contributor intends to change that 
contract. If conversion is intentional, spell out the nested object/list 
mapping and migration in both language docs and incompatible-changes, and pin 
the actual request bytes in the existing HTTP integration test. 
application/json should continue to preserve the configured JSON body. This 
qualifies my compatibility statement and the existing contract/coverage 
requests; it is not a second full review or a claim that a fix has landed. The 
prior source blockers remain, even with green CI. Happy to discuss which 
request contract the endpoint needs.



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

Reply via email to