Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Properly use headers from RestMulti when the datasource is empty.

Signed-off-by: Pierre Adam <[email protected]>
(cherry picked from commit 7230239)
  • Loading branch information
PierreAdam authored and gsmet committed Apr 2, 2024
1 parent 0048d6d commit 9b6b31c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ public Multi<Message> multiNdJson2() {
Wrapper::getStatus);
}

@Path("restmulti/empty")
@GET
@Produces(RestMediaType.APPLICATION_JSON)
public Multi<Message> restMultiEmptyJson() {
return RestMulti.fromUniResponse(
Uni.createFrom().item(
() -> new Wrapper(Multi.createFrom().empty(),
new AbstractMap.SimpleEntry<>("foo", "bar"), 222)),
Wrapper::getData,
Wrapper::getHeaders,
Wrapper::getStatus);
}

@Path("stream-json/multi")
@GET
@Produces(RestMediaType.APPLICATION_STREAM_JSON)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ public void testNdJsonMultiFromMulti2() {
.header("foo", "bar");
}

@Test
public void testRestMultiEmptyJson() {
when().get(uri.toString() + "streams/restmulti/empty")
.then().statusCode(222)
.body(is("[]"))
.header("foo", "bar");
}

@Test
public void testStreamJsonMultiFromMulti() {
when().get(uri.toString() + "streams/stream-json/multi")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private List<StreamingResponseCustomizer> determineCustomizers(boolean isFirst)
@Override
public void onComplete() {
if (!hadItem) {
StreamingUtil.setHeaders(requestContext, requestContext.serverResponse(), staticCustomizers);
StreamingUtil.setHeaders(requestContext, requestContext.serverResponse(), this.determineCustomizers(true));
}
if (json) {
String postfix = onCompleteText();
Expand Down

0 comments on commit 9b6b31c

Please sign in to comment.