Код: Выделить всё
void sendMultipleRequestsOnSameConnection() throws URISyntaxException, InterruptedException, ExecutionException {
HttpRequest httpRequest = HttpRequest.newBuilder()
.POST(BodyPublishers.ofString("LOREM"))
.uri(new URI("http://127.0.0.1/wait2"))
.version(Version.HTTP_1_1)
.build();
HttpRequest httpRequest2 = HttpRequest.newBuilder()
.POST(BodyPublishers.ofString("LOREM"))
.uri(new URI("http://127.0.0.1/wait"))
.version(Version.HTTP_1_1)
.build();
CompletableFuture future1 = httpClient.sendAsync(httpRequest, BodyHandlers.ofString());
Thread.sleep(500);
CompletableFuture future2 = httpClient.sendAsync(httpRequest2, BodyHandlers.ofString());
Этот тест работает должным образом:
Код: Выделить всё
@Test
void sendMultipleRequestsOnSameConnection() throws URISyntaxException, IOException, InterruptedException {
HttpRequest httpRequest = HttpRequest.newBuilder()
.POST(BodyPublishers.ofString("LOREM"))
.uri(new URI("http://127.0.0.1/"))
.version(Version.HTTP_1_1)
.build();
String responseBody1 = httpClient.send(httpRequest, BodyHandlers.ofString()).body();
String responseBody2 = httpClient.send(httpRequest, BodyHandlers.ofString()).body();
Assertions.assertEquals("HELLO WORLD", responseBody1);
Assertions.assertEquals("HELLO WORLD", responseBody2);
}
это ссылка на репозиторий: https: //github.com/dev-rifaii/http-from-scratch/tree/pipelining
Подробнее здесь: https://stackoverflow.com/questions/789 ... connection