Skip to content

Commit

Permalink
forcing multipart overrides headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ryber committed Aug 23, 2022
1 parent 5a5486e commit d152ee9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion unirest/src/main/java/kong/unirest/Headers.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ public ProgressMonitor getMonitor() {

MultipartBody forceMultiPart(boolean value) {
forceMulti = value;
headers.remove("Content-Type");
return this;
}
}
18 changes: 18 additions & 0 deletions unirest/src/test/java/BehaviorTests/MultiPartFormPostingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d152ee9

Please sign in to comment.