| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -225,8 +225,7 @@ private static HttpRequestBase prepareRequest(HttpRequest request, boolean async | |||
| 225 | 225 | if (request.getBody() != null) { | |
| 226 | 226 | HttpEntity entity = request.getBody().getEntity(); | |
| 227 | 227 | if (async) { | |
| 228 | - | ||
| 229 | - if (reqObj.getHeaders(CONTENT_TYPE) == null) { | ||
| 228 | + if (reqObj.getHeaders(CONTENT_TYPE) == null || reqObj.getHeaders(CONTENT_TYPE).length == 0) { | ||
| 230 | 229 | reqObj.setHeader(entity.getContentType()); | |
| 231 | 230 | } | |
| 232 | 231 | try { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -499,7 +499,40 @@ public void cancelled() { | |||
| 499 | 499 | } | |
| 500 | 500 | }); | |
| 501 | 501 | ||
| 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); | ||
| 503 | 536 | assertTrue(status); | |
| 504 | 537 | } | |
| 505 | 538 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments