从 移动quarkus-websocket
到之后quarkus-websockets-next
,任何对路径的 HTTP GET@WebSocket
现在都会出现错误
"Connection" header must be "Upgrade"
这是因为新的扩展会拦截每个匹配的请求并将其视为 WebSocket 握手。
在旧quarkus-websocket
模型中,@ServerEndpoint
仅处理真正的 WebSocket 升级;对同一 URL 的普通 GET 将会传递到 JAX-RS 资源。
使用quarkus-websockets-next
,@WebSocket(path="/…")
会为该路径上的所有 HTTP 方法安装一个 Vert.x 处理程序。缺少必需的 Connection: Upgrade 标头的标准 GET 请求会被捕获并拒绝,导致任何 REST 逻辑无法运行。
下面是一个最小的 Quarkus 项目,显示:
遗产(
quarkus-websockets
):- REST
@GET /chat
端点 - JSR-356 WebSocket
@ServerEndpoint("/chat")
→ GET有效(200 OK
),WS有效
- REST
下一个(
quarkus-websockets-next
):- 相同的 REST 资源
- 新建
@WebSocket(path = "/chat")
→ AnyGET /chat
现在失败
"Connection" header must be "Upgrade"
样本复现使用:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-websockets</artifactId>
</dependency>
ChatResource.java
:
@Path("/chat")
@ApplicationScoped
public class ChatResource {
@GET
public String hello() {
return "Hello from REST!";
}
}
ChatEndpoint.java
:
@ServerEndpoint("/chat")
@ApplicationScoped
public class ChatEndpoint {
@OnOpen
public void onOpen(Session session) { /*...*/ }
@OnMessage
public void onMessage(Session session, String msg) {
session.getAsyncRemote().sendText("Echo:" + msg);
}
}
行为
GET http://localhost:8080/chat → 200 OK,返回“Hello from REST!”
ws://localhost:8080/chat → WebSocket 握手成功
随着新的quarkus-websockets-next
:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-websockets-next</artifactId>
</dependency>
ChatResource.java (unchanged)
:
@Path("/chat")
@ApplicationScoped
public class ChatResource {
@GET
public String hello() {
return "Hello from REST!";
}
}
ChatSocket.java
:
@WebSocket(path = "/chat")
@ApplicationScoped
public class ChatSocket {
@OnOpen
public void onOpen(WebSocketConnection conn) { /*...*/ }
@OnMessage
public void onMessage(WebSocketConnection conn, String msg) {
conn.sendText("Echo:" + msg).subscribe().with(r -> {}, t -> {});
}
}
行为
GET http://localhost:8080/chat → 失败
"Connection" header must be "Upgrade"
ws://localhost:8080/chat → WebSocket 握手成功
这是预期结果quarkus-websockets-next
还是一个 bug?因为我正在为标准规范实现一些端点,这些端点可能类似于:
/queries/{queryName}/events
根据规范,它应该执行以下操作:
Returns all events that match the query or creates a new Websocket subscription.
之前这个功能正常,quarkus-websockets
但现在 GET 请求失败了,这quarkus-websockets-next
有点令人困惑,这是否是一个需要修复的问题。