Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ protected void customizeHeaders(HttpHeaders headers, Throwable throwable, HttpOu
}

protected final void sendMetadata(HttpMetadata metadata) {
if (headerSent) {
return;
}
getHttpChannel().writeHeader(metadata);
headerSent = true;
if (LOGGER.isDebugEnabled()) {
Expand Down Expand Up @@ -327,6 +330,10 @@ protected String getContentType() {
return responseEncoder.contentType();
}

protected boolean isHeaderSent() {
return headerSent;
}

protected void customizeTrailers(HttpHeaders headers, Throwable throwable) {
List<BiConsumer<HttpHeaders, Throwable>> trailersCustomizers = this.trailersCustomizers;
if (trailersCustomizers != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public void setResponseEncoder(HttpMessageEncoder responseEncoder) {
super.setResponseEncoder(new ServerSentEventEncoder(responseEncoder));
}

@Override
protected void doOnCompleted(Throwable throwable) {
if (!isHeaderSent()) {
sendMetadata(encodeHttpMetadata(true));
}
super.doOnCompleted(throwable);
}

@Override
protected HttpMetadata encodeHttpMetadata(boolean endStream) {
return super.encodeHttpMetadata(endStream)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,13 @@ protected HttpMetadata encodeHttpMetadata(boolean endStream) {
return super.encodeHttpMetadata(endStream)
.header(HttpHeaderNames.CACHE_CONTROL.getKey(), HttpConstants.NO_CACHE);
}

@Override
protected void doOnCompleted(Throwable throwable) {
// if throwable is not null, the header will be flushed by super.doOnCompleted(throwable)
if (!isHeaderSent() && throwable == null) {
sendMetadata(encodeHttpMetadata(true));
}
super.doOnCompleted(throwable);
}
}
Loading