Skip to content

Commit

Permalink
Merge pull request #846 from zalando/bugfix/empty-chunk
Browse files Browse the repository at this point in the history
Fixes chunking of empty bodies.
  • Loading branch information
Willi Schönborn authored Sep 29, 2020
2 parents 7b87133 + 71e4be5 commit e9c7ea1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public void write(final Correlation correlation, final HttpRequest request, fina
}

private Stream<String> chunk(final HttpMessage message) throws IOException {
if (message.getBodyAsString().isEmpty()) {
return Stream.of("");
}

return stream(new ChunkingSpliterator(message.getBodyAsString(), minChunkSize, maxChunkSize), false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> strings = captureRequest("");

assertThat(strings, contains(
allOf(startsWith("Incoming Request"))
));
}

@Test
void shouldWriteSingleRequestIfLengthNotExceeded() throws IOException {
final List<String> chunks = captureRequest("HelloWorld");
Expand Down

0 comments on commit e9c7ea1

Please sign in to comment.