diff --git a/logbook-core/src/main/java/org/zalando/logbook/ChunkingSink.java b/logbook-core/src/main/java/org/zalando/logbook/ChunkingSink.java index b5676309a..617786f22 100644 --- a/logbook-core/src/main/java/org/zalando/logbook/ChunkingSink.java +++ b/logbook-core/src/main/java/org/zalando/logbook/ChunkingSink.java @@ -48,6 +48,10 @@ public void write(final Correlation correlation, final HttpRequest request, fina } private Stream chunk(final HttpMessage message) throws IOException { + if (message.getBodyAsString().isEmpty()) { + return Stream.of(""); + } + return stream(new ChunkingSpliterator(message.getBodyAsString(), minChunkSize, maxChunkSize), false); } diff --git a/logbook-core/src/test/java/org/zalando/logbook/ChunkingSinkTest.java b/logbook-core/src/test/java/org/zalando/logbook/ChunkingSinkTest.java index 13bfe06dd..76ea51672 100644 --- a/logbook-core/src/test/java/org/zalando/logbook/ChunkingSinkTest.java +++ b/logbook-core/src/test/java/org/zalando/logbook/ChunkingSinkTest.java @@ -29,10 +29,19 @@ final class ChunkingSinkTest { private final Sink unit = new ChunkingSink(delegate, 20); @Test - void shouldDelegateActive() { + void delegatesActive() { assertThat(unit.isActive(), is(false)); } + @Test + void ignoresEmptyBodies() throws IOException { + final List strings = captureRequest(""); + + assertThat(strings, contains( + allOf(startsWith("Incoming Request")) + )); + } + @Test void shouldWriteSingleRequestIfLengthNotExceeded() throws IOException { final List chunks = captureRequest("HelloWorld");