diff --git a/unirest/src/main/java/kong/unirest/Headers.java b/unirest/src/main/java/kong/unirest/Headers.java index e80c959f..0edd7fd5 100644 --- a/unirest/src/main/java/kong/unirest/Headers.java +++ b/unirest/src/main/java/kong/unirest/Headers.java @@ -73,7 +73,11 @@ public void replace(String name, String value) { add(name, value); } - private void remove(String name) { + /** + * Remove a header + * @param name the header name to remove + */ + public void remove(String name) { headers.removeIf(h -> isName(h, name)); } diff --git a/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java b/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java index 0fda29ef..1c4e8a50 100644 --- a/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java +++ b/unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java @@ -201,6 +201,7 @@ public ProgressMonitor getMonitor() { MultipartBody forceMultiPart(boolean value) { forceMulti = value; + headers.remove("Content-Type"); return this; } } diff --git a/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java b/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java index f66afde2..6db1119d 100644 --- a/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java +++ b/unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java @@ -56,6 +56,24 @@ void overridingContentType(){ .assertHeader("Content-Type", "multipart/form-data"); } + @Test + void overridingForcingMultiTypeOverridesHeader(){ + Unirest.config().setDefaultHeader("Accept", "application/json") + .setDefaultHeader("Content-Type", "application/json") + .setDefaultHeader("Authorization", "Bearer xxx-abc-123"); + + Unirest.post(MockServer.POST) + .basicAuth("username", "password") + .multiPartContent() + .field("username", "xxx") + .field("token", "abc") + .field("grant_type", "password") + .asObject(RequestCapture.class) + .getBody() + .assertHeaderSize("Content-Type", 1) + .assertMultiPartContentType(); + } + @Test void testMultipart() throws Exception { Unirest.post(MockServer.POST)