From 906ac233a259933defc3c6e586e272ffea5d14e4 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Fri, 3 Jan 2014 11:11:08 +0100 Subject: [PATCH] [#2088] Introduce sendUnsupportedVersionResponse(...) methods which allows to use the ChannelFuture/ChannelPromise to get notified once the response was send. Also mark the old method as deprecated. --- .../WebSocketServerHandshakerFactory.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerFactory.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerFactory.java index 47299f39e8..c6f7b7a41d 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerFactory.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerFactory.java @@ -16,6 +16,8 @@ package io.netty.handler.codec.http.websocketx; import io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelPromise; import io.netty.handler.codec.http.DefaultHttpResponse; import io.netty.handler.codec.http.HttpHeaders.Names; import io.netty.handler.codec.http.HttpRequest; @@ -108,16 +110,28 @@ public class WebSocketServerHandshakerFactory { } /** - * Return that we need cannot not support the web socket version - * - * @param channel - * Channel + * @deprecated use {@link #sendUnsupportedVersionResponse(Channel)} */ + @Deprecated public static void sendUnsupportedWebSocketVersionResponse(Channel channel) { + sendUnsupportedVersionResponse(channel); + } + + /** + * Return that we need cannot not support the web socket version + */ + public static ChannelFuture sendUnsupportedVersionResponse(Channel channel) { + return sendUnsupportedVersionResponse(channel, channel.newPromise()); + } + + /** + * Return that we need cannot not support the web socket version + */ + public static ChannelFuture sendUnsupportedVersionResponse(Channel channel, ChannelPromise promise) { HttpResponse res = new DefaultHttpResponse( HttpVersion.HTTP_1_1, HttpResponseStatus.UPGRADE_REQUIRED); res.headers().set(Names.SEC_WEBSOCKET_VERSION, WebSocketVersion.V13.toHttpHeaderValue()); - channel.write(res); + return channel.write(res, promise); } }