Upgrade Jetty and harden WebSocket upgrade lifecycle
This commit is contained in:
@@ -42,9 +42,10 @@ public abstract class Response {
|
||||
protected String content_type;
|
||||
protected Integer status;
|
||||
protected ResponseState state = ResponseState.CREATED;
|
||||
protected final ArrayList<HTTP.Header> headers=new ArrayList<>();
|
||||
protected final ArrayList<HTTP.Cookie> cookies=new ArrayList<>();
|
||||
protected CompletableFuture<Object> promise;
|
||||
protected final ArrayList<HTTP.Header> headers=new ArrayList<>();
|
||||
protected final ArrayList<HTTP.Cookie> cookies=new ArrayList<>();
|
||||
protected CompletableFuture<Object> promise;
|
||||
protected boolean upgradedToWebSocket;
|
||||
|
||||
protected Response(Request request) {
|
||||
this.request = request;
|
||||
@@ -154,9 +155,13 @@ public abstract class Response {
|
||||
|
||||
public abstract void complete();
|
||||
|
||||
public boolean isPromised() {
|
||||
return promise!=null;
|
||||
}
|
||||
public boolean isPromised() {
|
||||
return promise!=null;
|
||||
}
|
||||
|
||||
public boolean isUpgradedToWebSocket() {
|
||||
return upgradedToWebSocket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate an async promise chain using supplyAsync.
|
||||
@@ -268,5 +273,5 @@ public abstract class Response {
|
||||
*
|
||||
* TODO: Implement in ServletResponse using Jakarta WebSocket API
|
||||
*/
|
||||
public abstract WebSocketSession upgradeToWebSocket(String route, Session appSession) throws IOException;
|
||||
}
|
||||
public abstract WebSocketSession upgradeToWebSocket(String route, Session appSession) throws IOException;
|
||||
}
|
||||
|
||||
@@ -236,7 +236,9 @@ public class JettyApp extends App implements Servlet {
|
||||
// Only end session if not async (async will end session when completing)
|
||||
if(resp.isPromised()==false){
|
||||
ss.end();
|
||||
resp.complete();
|
||||
if(!resp.isUpgradedToWebSocket()){
|
||||
resp.complete();
|
||||
}
|
||||
}else{
|
||||
resp.promiseLast((result, error) -> {
|
||||
if(result instanceof Exception){
|
||||
|
||||
@@ -186,6 +186,7 @@ public class ServletResponse extends Response {
|
||||
*/
|
||||
@Override
|
||||
public com.reliancy.jabba.WebSocketSession upgradeToWebSocket(String route, com.reliancy.jabba.Session appSession) throws IOException {
|
||||
upgradedToWebSocket=true;
|
||||
return ServletWebSocketSession.create(this,route, appSession);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user