Skip to content

Commit d152ee9

Browse files
committed
forcing multipart overrides headers
1 parent 5a5486e commit d152ee9

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

unirest/src/main/java/kong/unirest/Headers.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ public void replace(String name, String value) {
7373
add(name, value);
7474
}
7575

76-
private void remove(String name) {
76+
/**
77+
* Remove a header
78+
* @param name the header name to remove
79+
*/
80+
public void remove(String name) {
7781
headers.removeIf(h -> isName(h, name));
7882
}
7983

unirest/src/main/java/kong/unirest/HttpRequestMultiPart.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ public ProgressMonitor getMonitor() {
201201

202202
MultipartBody forceMultiPart(boolean value) {
203203
forceMulti = value;
204+
headers.remove("Content-Type");
204205
return this;
205206
}
206207
}

unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ void overridingContentType(){
5656
.assertHeader("Content-Type", "multipart/form-data");
5757
}
5858

59+
@Test
60+
void overridingForcingMultiTypeOverridesHeader(){
61+
Unirest.config().setDefaultHeader("Accept", "application/json")
62+
.setDefaultHeader("Content-Type", "application/json")
63+
.setDefaultHeader("Authorization", "Bearer xxx-abc-123");
64+
65+
Unirest.post(MockServer.POST)
66+
.basicAuth("username", "password")
67+
.multiPartContent()
68+
.field("username", "xxx")
69+
.field("token", "abc")
70+
.field("grant_type", "password")
71+
.asObject(RequestCapture.class)
72+
.getBody()
73+
.assertHeaderSize("Content-Type", 1)
74+
.assertMultiPartContentType();
75+
}
76+
5977
@Test
6078
void testMultipart() throws Exception {
6179
Unirest.post(MockServer.POST)

0 commit comments

Comments
 (0)