File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
avaje-jex/src/main/java/io/avaje/jex/http/sse Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import java .io .IOException ;
4
4
import java .io .UncheckedIOException ;
5
+ import java .util .Optional ;
5
6
import java .util .function .Consumer ;
6
7
7
8
import io .avaje .jex .core .Constants ;
@@ -22,9 +23,13 @@ final class SseHandler implements ExchangeHandler {
22
23
@ Override
23
24
public void handle (Context ctx ) throws Exception {
24
25
25
- if (!TEXT_EVENT_STREAM .equals (ctx .header (Constants .ACCEPT ))) {
26
- throw new BadRequestException ("SSE Requests must have an 'Accept: text/event-stream' header" );
27
- }
26
+ Optional .ofNullable (ctx .header (Constants .ACCEPT ))
27
+ .filter (s -> s .contains (TEXT_EVENT_STREAM ))
28
+ .orElseThrow (
29
+ () ->
30
+ new BadRequestException (
31
+ "SSE Requests must have an 'Accept: text/event-stream' header" ));
32
+
28
33
final var exchange = ctx .exchange ();
29
34
final var headers = exchange .getResponseHeaders ();
30
35
headers .add (Constants .CONTENT_TYPE , TEXT_EVENT_STREAM );
You can’t perform that action at this time.
0 commit comments