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) {
585
585
final HttpResponse <Stream <String >> res = handler (HttpResponse .BodyHandlers .ofLines ());
586
586
this .httpResponse = res ;
587
587
checkResponse (res );
588
- return res .body ().map (bodyReader ::readBody );
588
+ return res .body ().filter ( line -> ! line . isEmpty ()). map (bodyReader ::readBody );
589
589
}
590
590
591
591
@ Override
Original file line number Diff line number Diff line change @@ -271,6 +271,18 @@ void get_stream_as() {
271
271
assertThat (first .name ).isEqualTo ("one" );
272
272
}
273
273
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
+
274
286
@ Test
275
287
void get_stream_NotFoundException () {
276
288
clientContext .metrics (true );
Original file line number Diff line number Diff line change @@ -52,6 +52,11 @@ private void routes(JavalinDefaultRouting cfg) {
52
52
controller .stream (ctx );
53
53
});
54
54
55
+ cfg .get ("/hello/streamEmpty" , ctx -> {
56
+ ctx .status (200 );
57
+ controller .streamEmpty (ctx );
58
+ });
59
+
55
60
cfg .get ("/hello/{id}/{date}" , ctx -> {
56
61
ctx .status (200 );
57
62
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) {
63
63
context .result (content );
64
64
}
65
65
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
+
66
73
/**
67
74
* Return the Hello DTO.
68
75
*
You can’t perform that action at this time.
0 commit comments