Upgrade Jetty and harden WebSocket upgrade lifecycle

This commit is contained in:
Amer Agovic
2026-05-01 13:47:23 -05:00
parent c86fc03c2e
commit bfb6ff82bf
4 changed files with 18 additions and 10 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ tasks.withType(JavaCompile) {
} }
dependencies { dependencies {
def jettyVersion="12.0.15" def jettyVersion="12.0.32"
def bstoreVersion="1.0.0-SNAPSHOT" def bstoreVersion="1.0.0-SNAPSHOT"
implementation "org.eclipse.jetty:jetty-server:${jettyVersion}" implementation "org.eclipse.jetty:jetty-server:${jettyVersion}"
implementation "org.eclipse.jetty.http2:jetty-http2-server:${jettyVersion}" implementation "org.eclipse.jetty.http2:jetty-http2-server:${jettyVersion}"
+13 -8
View File
@@ -42,9 +42,10 @@ public abstract class Response {
protected String content_type; protected String content_type;
protected Integer status; protected Integer status;
protected ResponseState state = ResponseState.CREATED; protected ResponseState state = ResponseState.CREATED;
protected final ArrayList<HTTP.Header> headers=new ArrayList<>(); protected final ArrayList<HTTP.Header> headers=new ArrayList<>();
protected final ArrayList<HTTP.Cookie> cookies=new ArrayList<>(); protected final ArrayList<HTTP.Cookie> cookies=new ArrayList<>();
protected CompletableFuture<Object> promise; protected CompletableFuture<Object> promise;
protected boolean upgradedToWebSocket;
protected Response(Request request) { protected Response(Request request) {
this.request = request; this.request = request;
@@ -154,9 +155,13 @@ public abstract class Response {
public abstract void complete(); public abstract void complete();
public boolean isPromised() { public boolean isPromised() {
return promise!=null; return promise!=null;
} }
public boolean isUpgradedToWebSocket() {
return upgradedToWebSocket;
}
/** /**
* Initiate an async promise chain using supplyAsync. * Initiate an async promise chain using supplyAsync.
@@ -268,5 +273,5 @@ public abstract class Response {
* *
* TODO: Implement in ServletResponse using Jakarta WebSocket API * 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) // Only end session if not async (async will end session when completing)
if(resp.isPromised()==false){ if(resp.isPromised()==false){
ss.end(); ss.end();
resp.complete(); if(!resp.isUpgradedToWebSocket()){
resp.complete();
}
}else{ }else{
resp.promiseLast((result, error) -> { resp.promiseLast((result, error) -> {
if(result instanceof Exception){ if(result instanceof Exception){
@@ -186,6 +186,7 @@ public class ServletResponse extends Response {
*/ */
@Override @Override
public com.reliancy.jabba.WebSocketSession upgradeToWebSocket(String route, com.reliancy.jabba.Session appSession) throws IOException { public com.reliancy.jabba.WebSocketSession upgradeToWebSocket(String route, com.reliancy.jabba.Session appSession) throws IOException {
upgradedToWebSocket=true;
return ServletWebSocketSession.create(this,route, appSession); return ServletWebSocketSession.create(this,route, appSession);
} }
} }