Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ private <T> Stream<T> stream(BodyReader<T> bodyReader) {
final HttpResponse<Stream<String>> res = handler(HttpResponse.BodyHandlers.ofLines());
this.httpResponse = res;
checkResponse(res);
return res.body().map(bodyReader::readBody);
return res.body().filter(line -> !line.isEmpty()).map(bodyReader::readBody);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,18 @@ void get_stream_as() {
assertThat(first.name).isEqualTo("one");
}

@Test
void get_stream_as_when_empty() {
final HttpResponse<Stream<SimpleData>> res = clientContext.request()
.path("hello").path("streamEmpty")
.GET()
.asStream(SimpleData.class);

assertThat(res.statusCode()).isEqualTo(200);
final List<SimpleData> data = res.body().collect(Collectors.toList());
assertThat(data).isEmpty();
}

@Test
void get_stream_NotFoundException() {
clientContext.metrics(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ private void routes(JavalinDefaultRouting cfg) {
controller.stream(ctx);
});

cfg.get("/hello/streamEmpty", ctx -> {
ctx.status(200);
controller.streamEmpty(ctx);
});

cfg.get("/hello/{id}/{date}", ctx -> {
ctx.status(200);
final int id = asInt(ctx.pathParam("id"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ void stream(Context context) {
context.result(content);
}

@Get("streamEmpty")
void streamEmpty(Context context) {
// simulate x-json-stream response with empty stream
context.header("content-type", "application/x-json-stream");
context.result("\n");
}

/**
* Return the Hello DTO.
*
Expand Down