Skip to content

Commit 24fdf52

Browse files
committed
fixing tests
1 parent f5b7c28 commit 24fdf52

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/main/java/com/mashape/unirest/http/HttpClientHelper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,7 @@ private static HttpRequestBase prepareRequest(HttpRequest request, boolean async
225225
if (request.getBody() != null) {
226226
HttpEntity entity = request.getBody().getEntity();
227227
if (async) {
228-
229-
if (reqObj.getHeaders(CONTENT_TYPE) == null) {
228+
if (reqObj.getHeaders(CONTENT_TYPE) == null || reqObj.getHeaders(CONTENT_TYPE).length == 0) {
230229
reqObj.setHeader(entity.getContentType());
231230
}
232231
try {

src/test/java/com/mashape/unirest/test/http/UnirestTest.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,40 @@ public void cancelled() {
499499
}
500500
});
501501

502-
lock.await(100000, TimeUnit.SECONDS);
502+
lock.await(10, TimeUnit.SECONDS);
503+
assertTrue(status);
504+
}
505+
506+
@Test
507+
public void testAsyncCustomContentTypeAndFormParams() throws InterruptedException {
508+
Unirest.post("http://httpbin.org/post")
509+
.header("accept", "application/json")
510+
.header("Content-Type", "application/x-www-form-urlencoded")
511+
.field("name", "Mark")
512+
.field("hello", "world")
513+
.asJsonAsync(new Callback<JsonNode>() {
514+
515+
public void failed(UnirestException e) {
516+
fail();
517+
}
518+
519+
public void completed(HttpResponse<JsonNode> jsonResponse) {
520+
JsonNode json = jsonResponse.getBody();
521+
assertEquals("Mark", json.getObject().getJSONObject("form").getString("name"));
522+
assertEquals("world", json.getObject().getJSONObject("form").getString("hello"));
523+
524+
assertEquals("application/x-www-form-urlencoded", json.getObject().getJSONObject("headers").getString("Content-Type"));
525+
526+
status = true;
527+
lock.countDown();
528+
}
529+
530+
public void cancelled() {
531+
fail();
532+
}
533+
});
534+
535+
lock.await(10, TimeUnit.SECONDS);
503536
assertTrue(status);
504537
}
505538
}

0 commit comments

Comments
 (0)