File tree Expand file tree Collapse file tree 4 files changed +25
-1
lines changed
main/java/io/avaje/http/client Expand file tree Collapse file tree 4 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -585,7 +585,7 @@ private <T> Stream<T> stream(BodyReader<T> bodyReader) {
585585 final HttpResponse <Stream <String >> res = handler (HttpResponse .BodyHandlers .ofLines ());
586586 this .httpResponse = res ;
587587 checkResponse (res );
588- return res .body ().map (bodyReader ::readBody );
588+ return res .body ().filter ( line -> ! line . isEmpty ()). map (bodyReader ::readBody );
589589 }
590590
591591 @ Override
Original file line number Diff line number Diff line change @@ -271,6 +271,18 @@ void get_stream_as() {
271271 assertThat (first .name ).isEqualTo ("one" );
272272 }
273273
274+ @ Test
275+ void get_stream_as_when_empty () {
276+ final HttpResponse <Stream <SimpleData >> res = clientContext .request ()
277+ .path ("hello" ).path ("streamEmpty" )
278+ .GET ()
279+ .asStream (SimpleData .class );
280+
281+ assertThat (res .statusCode ()).isEqualTo (200 );
282+ final List <SimpleData > data = res .body ().collect (Collectors .toList ());
283+ assertThat (data ).isEmpty ();
284+ }
285+
274286 @ Test
275287 void get_stream_NotFoundException () {
276288 clientContext .metrics (true );
Original file line number Diff line number Diff line change @@ -52,6 +52,11 @@ private void routes(JavalinDefaultRouting cfg) {
5252 controller .stream (ctx );
5353 });
5454
55+ cfg .get ("/hello/streamEmpty" , ctx -> {
56+ ctx .status (200 );
57+ controller .streamEmpty (ctx );
58+ });
59+
5560 cfg .get ("/hello/{id}/{date}" , ctx -> {
5661 ctx .status (200 );
5762 final int id = asInt (ctx .pathParam ("id" ));
Original file line number Diff line number Diff line change @@ -63,6 +63,13 @@ void stream(Context context) {
6363 context .result (content );
6464 }
6565
66+ @ Get ("streamEmpty" )
67+ void streamEmpty (Context context ) {
68+ // simulate x-json-stream response with empty stream
69+ context .header ("content-type" , "application/x-json-stream" );
70+ context .result ("\n " );
71+ }
72+
6673 /**
6774 * Return the Hello DTO.
6875 *
You can’t perform that action at this time.
0 commit comments