Skip to content

Commit

Permalink
issue #528 reset content headers when multiPartContent is called
Browse files Browse the repository at this point in the history
  • Loading branch information
ryber committed Jul 24, 2024
1 parent dbe42b7 commit c234bf0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -492,4 +492,23 @@ void settingTheBoundary() {
});

}

@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();
}
}
6 changes: 5 additions & 1 deletion unirest/src/main/java/kong/unirest/core/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 by name
* @param name the name of the header
*/
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 @@ -231,6 +231,7 @@ public ProgressMonitor getMonitor() {

MultipartBody forceMultiPart(boolean value) {
forceMulti = value;
headers.remove("Content-Type");
return this;
}
}

0 comments on commit c234bf0

Please sign in to comment.