From e23cf7c9eb5ebc55e30001f913e8fff7f4f449a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=A9=E5=AD=90=E8=88=AA?= <1617036662@qq.com> Date: Mon, 4 Sep 2023 09:30:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0websocket=E5=93=8D=E5=BA=94?= =?UTF-8?q?=E5=A4=B4Sec-WebSocket-Protocol=E8=BF=94=E5=9B=9E=EF=BC=8C?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E5=B8=A6token=E6=94=BE=E5=9C=A8=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E5=A4=B4=EF=BC=8C=E5=90=8E=E7=AB=AF=E8=A6=81=E5=B0=86?= =?UTF-8?q?=E6=AD=A4token=E6=94=BE=E5=9C=A8=E5=93=8D=E5=BA=94=E5=A4=B4?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=EF=BC=8C=E4=B8=8D=E7=84=B6=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E6=96=AD=E5=BC=80=E8=BF=9E=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/yeauty/standard/HttpServerHandler.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/yeauty/standard/HttpServerHandler.java b/src/main/java/org/yeauty/standard/HttpServerHandler.java index 820e61b..bda44da 100755 --- a/src/main/java/org/yeauty/standard/HttpServerHandler.java +++ b/src/main/java/org/yeauty/standard/HttpServerHandler.java @@ -241,7 +241,15 @@ private void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest req) { pipeline.addLast(new WebSocketServerHandler(pojoEndpointServer)); } String finalPattern = pattern; - handshaker.handshake(channel, req).addListener(future -> { + + String header = headers.get(HttpHeaders.Names.SEC_WEBSOCKET_PROTOCOL); + HttpHeaders httpHeaders = null; + if (header!=null) { + httpHeaders = new DefaultHttpHeaders().add(HttpHeaders.Names.SEC_WEBSOCKET_PROTOCOL, header); + } + final ChannelFuture handshakeFuture = handshaker.handshake(ctx.channel(), req,httpHeaders,ctx.channel().newPromise()); + + handshakeFuture.addListener((ChannelFutureListener) future -> { if (future.isSuccess()) { if (isCors) { pipeline.remove(CorsHandler.class); @@ -277,4 +285,4 @@ private static String getWebSocketLocation(FullHttpRequest req) { String location = req.headers().get(HttpHeaderNames.HOST) + req.uri(); return "ws://" + location; } -} \ No newline at end of file +}