diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java index bc4478eecb3..c160ec77402 100644 --- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java +++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java @@ -1562,7 +1562,6 @@ protected String setupHttpEntityEnclosingRequestData(HttpEntityEnclosingRequestB } // Write the request to our own stream MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create(); - multipartEntityBuilder.setCharset(charset); if (doBrowserCompatibleMultipart) { multipartEntityBuilder.setLaxMode(); } else { diff --git a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHTTPHC4Impl.java b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHTTPHC4Impl.java index 315806d1b87..bb5c2620c43 100644 --- a/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHTTPHC4Impl.java +++ b/src/protocol/http/src/test/java/org/apache/jmeter/protocol/http/sampler/TestHTTPHC4Impl.java @@ -97,6 +97,22 @@ void testFileargWithMimeTypeWithCharset() throws Exception { Assertions.assertTrue(requestData.contains("charset=utf-8")); } + @Test + void testMultipartFormHeaderWithoutCharset() throws Exception { + HTTPSamplerBase sampler = (HTTPSamplerBase) new HttpTestSampleGui().createTestElement(); + sampler.setThreadContext(jmctx); + sampler.setDoMultipart(true); + sampler.setDoBrowserCompatibleMultipart(true); + HttpEntityEnclosingRequestBase post = new HttpPost(); + post.addHeader(HTTPConstants.HEADER_CONTENT_TYPE, "application/json; charset=utf-8"); + sampler.setHTTPFiles(new HTTPFileArg[] {new HTTPFileArg("filename", "file", "application/octect; charset=utf-8")}); + HTTPHC4Impl hc = new HTTPHC4Impl(sampler); + String requestData = hc.setupHttpEntityEnclosingRequestData(post); + + String contentTypeWithEntity = post.getEntity().getContentType().getValue(); + Assertions.assertFalse(contentTypeWithEntity.contains("charset")); + } + @Test public void testNotifyFirstSampleAfterLoopRestartWhenThreadIterationIsSameUser() { jmvars.putObject(SAME_USER, true);