This is an automated email from the ASF dual-hosted git repository.
wanghailin pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/seatunnel.git
The following commit(s) were added to refs/heads/dev by this push:
new 4d7d765a26 [Fix][Connector-Http] fix Invalid mime type (#9363)
4d7d765a26 is described below
commit 4d7d765a26b1f9488abc54ccfe0a52b386c55255
Author: litiliu <[email protected]>
AuthorDate: Fri Jun 20 09:31:15 2025 +0800
[Fix][Connector-Http] fix Invalid mime type (#9363)
---
.../seatunnel/http/client/HttpClientProvider.java | 4 +-
.../http/client/HttpClientProviderTest.java | 53 ++++++++++++++++++++++
2 files changed, 54 insertions(+), 3 deletions(-)
diff --git
a/seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/client/HttpClientProvider.java
b/seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/client/HttpClientProvider.java
index 9ff294f59a..dedac81ab1 100644
---
a/seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/client/HttpClientProvider.java
+++
b/seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/client/HttpClientProvider.java
@@ -465,7 +465,7 @@ public class HttpClientProvider implements AutoCloseable {
headers.forEach(request::addHeader);
}
- private void addBody(HttpEntityEnclosingRequestBase request, Map<String,
Object> body)
+ static void addBody(HttpEntityEnclosingRequestBase request, Map<String,
Object> body)
throws UnsupportedEncodingException {
if (MapUtils.isEmpty(body)) {
body = new HashMap<>();
@@ -489,10 +489,8 @@ public class HttpClientProvider implements AutoCloseable {
request.setEntity(new UrlEncodedFormEntity(parameters,
ENCODING));
}
} else {
- request.addHeader(HTTP.CONTENT_TYPE, APPLICATION_JSON);
StringEntity entity =
new StringEntity(JsonUtils.toJsonString(body),
ContentType.APPLICATION_JSON);
- entity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,
APPLICATION_JSON));
request.setEntity(entity);
}
}
diff --git
a/seatunnel-connectors-v2/connector-http/connector-http-base/src/test/java/org/apache/seatunnel/connectors/seatunnel/http/client/HttpClientProviderTest.java
b/seatunnel-connectors-v2/connector-http/connector-http-base/src/test/java/org/apache/seatunnel/connectors/seatunnel/http/client/HttpClientProviderTest.java
new file mode 100644
index 0000000000..c2ebcff1ca
--- /dev/null
+++
b/seatunnel-connectors-v2/connector-http/connector-http-base/src/test/java/org/apache/seatunnel/connectors/seatunnel/http/client/HttpClientProviderTest.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.seatunnel.connectors.seatunnel.http.client;
+
+import org.apache.http.Header;
+import org.apache.http.client.methods.HttpPost;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+class HttpClientProviderTest {
+
+ @Test
+ void addBody() throws Exception {
+ HttpPost post = new HttpPost("http://localhost:8080");
+ Map<String, Object> body = new HashMap<>();
+ Header[] originalHeaders = post.getAllHeaders();
+ HttpClientProvider.addBody(post, body);
+
+ // ensure the original headers are preserved
+ Header[] currentHeaders = post.getAllHeaders();
+ Assertions.assertEquals(originalHeaders.length, currentHeaders.length);
+ for (int i = 0; i < originalHeaders.length; i++) {
+ Assertions.assertEquals(
+ originalHeaders[i].getName(),
+ currentHeaders[i].getName(),
+ "Header name mismatch at index " + i);
+ Assertions.assertEquals(
+ originalHeaders[i].getValue(),
+ currentHeaders[i].getValue(),
+ "Header value mismatch at index " + i);
+ }
+ // ensure no manually set content type or encoding
+ Assertions.assertNull(post.getEntity().getContentEncoding());
+ }
+}