[#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 e83d2e0b4e
commit 7d90c5b756

View File

@ -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);
}
}