[#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.
This commit is contained in:
Norman Maurer 2014-01-03 11:11:08 +01:00
parent 299ce22938
commit 906ac233a2

View File

@ -16,6 +16,8 @@
package io.netty.handler.codec.http.websocketx; package io.netty.handler.codec.http.websocketx;
import io.netty.channel.Channel; 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.DefaultHttpResponse;
import io.netty.handler.codec.http.HttpHeaders.Names; import io.netty.handler.codec.http.HttpHeaders.Names;
import io.netty.handler.codec.http.HttpRequest; 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 * @deprecated use {@link #sendUnsupportedVersionResponse(Channel)}
*
* @param channel
* Channel
*/ */
@Deprecated
public static void sendUnsupportedWebSocketVersionResponse(Channel channel) { 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( HttpResponse res = new DefaultHttpResponse(
HttpVersion.HTTP_1_1, HttpVersion.HTTP_1_1,
HttpResponseStatus.UPGRADE_REQUIRED); HttpResponseStatus.UPGRADE_REQUIRED);
res.headers().set(Names.SEC_WEBSOCKET_VERSION, WebSocketVersion.V13.toHttpHeaderValue()); res.headers().set(Names.SEC_WEBSOCKET_VERSION, WebSocketVersion.V13.toHttpHeaderValue());
channel.write(res); return channel.write(res, promise);
} }
} }