Add flush method to ServerHttpResponse
This is useful to make sure response headers are written to the underlying response. It is also useful in conjunction with long running, async requests and HTTP streaming, to ensure the Servlet response buffer is sent to the client without additional delay and also causes an IOException to be raised if the client has gone away.
This commit is contained in:
@@ -116,21 +116,35 @@ public class AsyncServletServerHttpRequest extends ServletServerHttpRequest
|
||||
// Implementation of AsyncListener methods
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public void onStartAsync(AsyncEvent event) throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(AsyncEvent event) throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTimeout(AsyncEvent event) throws IOException {
|
||||
for (Runnable handler : this.timeoutHandlers) {
|
||||
handler.run();
|
||||
try {
|
||||
for (Runnable handler : this.timeoutHandlers) {
|
||||
handler.run();
|
||||
}
|
||||
}
|
||||
catch (Throwable t) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete(AsyncEvent event) throws IOException {
|
||||
for (Runnable handler : this.completionHandlers) {
|
||||
handler.run();
|
||||
try {
|
||||
for (Runnable handler : this.completionHandlers) {
|
||||
handler.run();
|
||||
}
|
||||
}
|
||||
catch (Throwable t) {
|
||||
// ignore
|
||||
}
|
||||
this.asyncContext = null;
|
||||
this.asyncCompleted.set(true);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.http.server;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.springframework.http.HttpOutputMessage;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -35,6 +36,11 @@ public interface ServerHttpResponse extends HttpOutputMessage, Closeable {
|
||||
*/
|
||||
void setStatusCode(HttpStatus status);
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
void flush() throws IOException;
|
||||
|
||||
/**
|
||||
* Close this response, freeing any resources created.
|
||||
*/
|
||||
|
||||
@@ -80,6 +80,13 @@ public class ServletServerHttpResponse implements ServerHttpResponse {
|
||||
return this.servletResponse.getOutputStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
writeCookies();
|
||||
writeHeaders();
|
||||
this.servletResponse.flushBuffer();
|
||||
}
|
||||
|
||||
public void close() {
|
||||
writeCookies();
|
||||
writeHeaders();
|
||||
|
||||
Reference in New Issue
Block a user