Skip to content

Commit a54504c

Browse files
authored
[SSE] Relax SSE Accept Header Validation (#273)
* relax sse accept header Now will not throw an exception for multivalue accept headers * Update SseHandler.java
1 parent 2cef935 commit a54504c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

avaje-jex/src/main/java/io/avaje/jex/http/sse/SseHandler.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.IOException;
44
import java.io.UncheckedIOException;
5+
import java.util.Optional;
56
import java.util.function.Consumer;
67

78
import io.avaje.jex.core.Constants;
@@ -22,9 +23,13 @@ final class SseHandler implements ExchangeHandler {
2223
@Override
2324
public void handle(Context ctx) throws Exception {
2425

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+
2833
final var exchange = ctx.exchange();
2934
final var headers = exchange.getResponseHeaders();
3035
headers.add(Constants.CONTENT_TYPE, TEXT_EVENT_STREAM);

0 commit comments

Comments
 (0)