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


##########
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:
   Optional: with `application/x-www-form-urlencoded; charset=UTF-8` a nested 
body such as `{"data":{"type":1},"tags":[1,2]}` was sent as-is on dev and now 
goes out as `data->type=1&tags=[1, 2]`. Should nested objects stay verbatim, or 
at least be listed in incompatible-changes?



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