2011-09-26 14:51:15 +02:00
|
|
|
/*
|
2012-06-04 22:31:44 +02:00
|
|
|
* Copyright 2012 The Netty Project
|
2011-09-26 14:51:15 +02:00
|
|
|
*
|
2011-12-09 06:18:34 +01:00
|
|
|
* The Netty Project licenses this file to you under the Apache License,
|
|
|
|
* version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at:
|
2011-09-26 14:51:15 +02:00
|
|
|
*
|
2012-06-04 22:31:44 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-09-26 14:51:15 +02:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
2011-12-09 06:18:34 +01:00
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
2011-09-26 14:51:15 +02:00
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
2011-12-09 04:38:59 +01:00
|
|
|
package io.netty.handler.codec.http.websocketx;
|
2011-09-26 14:51:15 +02:00
|
|
|
|
|
|
|
import java.net.URI;
|
2011-12-15 04:00:36 +01:00
|
|
|
import java.util.Map;
|
2011-09-26 14:51:15 +02:00
|
|
|
|
2012-11-12 01:43:14 +01:00
|
|
|
import static io.netty.handler.codec.http.websocketx.WebSocketVersion.*;
|
|
|
|
|
2011-09-26 14:51:15 +02:00
|
|
|
/**
|
|
|
|
* Instances the appropriate handshake class to use for clients
|
|
|
|
*/
|
2012-12-12 06:57:03 +01:00
|
|
|
public final class WebSocketClientHandshakerFactory {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private constructor so this static class cannot be instanced.
|
|
|
|
*/
|
|
|
|
private WebSocketClientHandshakerFactory() {
|
|
|
|
}
|
2011-09-26 14:51:15 +02:00
|
|
|
|
2011-12-15 12:25:40 +01:00
|
|
|
/**
|
2012-05-31 02:13:00 +02:00
|
|
|
* Creates a new handshaker.
|
|
|
|
*
|
2011-12-15 12:25:40 +01:00
|
|
|
* @param webSocketURL
|
2012-06-08 12:28:12 +02:00
|
|
|
* URL for web socket communications. e.g "ws://myhost.com/mypath".
|
|
|
|
* Subsequent web socket frames will be sent to this URL.
|
2011-12-15 12:25:40 +01:00
|
|
|
* @param version
|
|
|
|
* Version of web socket specification to use to connect to the server
|
2012-01-19 05:12:45 +01:00
|
|
|
* @param subprotocol
|
2011-12-15 12:25:40 +01:00
|
|
|
* Sub protocol request sent to the server. Null if no sub-protocol support is required.
|
|
|
|
* @param allowExtensions
|
|
|
|
* Allow extensions to be used in the reserved bits of the web socket frame
|
|
|
|
* @param customHeaders
|
|
|
|
* Custom HTTP headers to send during the handshake
|
|
|
|
*/
|
2012-12-12 06:57:03 +01:00
|
|
|
public static WebSocketClientHandshaker newHandshaker(
|
2012-05-31 02:13:00 +02:00
|
|
|
URI webSocketURL, WebSocketVersion version, String subprotocol,
|
|
|
|
boolean allowExtensions, Map<String, String> customHeaders) {
|
|
|
|
return newHandshaker(webSocketURL, version, subprotocol, allowExtensions, customHeaders, 65536);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new handshaker.
|
|
|
|
*
|
|
|
|
* @param webSocketURL
|
2012-06-08 12:28:12 +02:00
|
|
|
* URL for web socket communications. e.g "ws://myhost.com/mypath".
|
|
|
|
* Subsequent web socket frames will be sent to this URL.
|
2012-05-31 02:13:00 +02:00
|
|
|
* @param version
|
|
|
|
* Version of web socket specification to use to connect to the server
|
|
|
|
* @param subprotocol
|
|
|
|
* Sub protocol request sent to the server. Null if no sub-protocol support is required.
|
|
|
|
* @param allowExtensions
|
|
|
|
* Allow extensions to be used in the reserved bits of the web socket frame
|
|
|
|
* @param customHeaders
|
|
|
|
* Custom HTTP headers to send during the handshake
|
|
|
|
* @param maxFramePayloadLength
|
2012-06-08 12:28:12 +02:00
|
|
|
* Maximum allowable frame payload length. Setting this value to your application's
|
|
|
|
* requirement may reduce denial of service attacks using long data frames.
|
2012-05-31 02:13:00 +02:00
|
|
|
*/
|
2012-12-12 06:57:03 +01:00
|
|
|
public static WebSocketClientHandshaker newHandshaker(
|
2012-05-31 02:13:00 +02:00
|
|
|
URI webSocketURL, WebSocketVersion version, String subprotocol,
|
2012-05-31 02:21:51 +02:00
|
|
|
boolean allowExtensions, Map<String, String> customHeaders, int maxFramePayloadLength) {
|
2012-11-12 01:43:14 +01:00
|
|
|
if (version == V13) {
|
2012-06-08 12:28:12 +02:00
|
|
|
return new WebSocketClientHandshaker13(
|
2012-11-12 01:43:14 +01:00
|
|
|
webSocketURL, V13, subprotocol, allowExtensions, customHeaders, maxFramePayloadLength);
|
2011-12-15 12:25:40 +01:00
|
|
|
}
|
2012-11-12 01:43:14 +01:00
|
|
|
if (version == V08) {
|
2012-06-08 12:28:12 +02:00
|
|
|
return new WebSocketClientHandshaker08(
|
2012-11-12 01:43:14 +01:00
|
|
|
webSocketURL, V08, subprotocol, allowExtensions, customHeaders, maxFramePayloadLength);
|
2011-12-15 12:25:40 +01:00
|
|
|
}
|
2012-12-14 23:59:18 +01:00
|
|
|
if (version == V07) {
|
|
|
|
return new WebSocketClientHandshaker07(
|
|
|
|
webSocketURL, V07, subprotocol, allowExtensions, customHeaders, maxFramePayloadLength);
|
|
|
|
}
|
2012-11-12 01:43:14 +01:00
|
|
|
if (version == V00) {
|
2012-06-08 12:28:12 +02:00
|
|
|
return new WebSocketClientHandshaker00(
|
2012-11-12 01:43:14 +01:00
|
|
|
webSocketURL, V00, subprotocol, customHeaders, maxFramePayloadLength);
|
2011-12-15 12:25:40 +01:00
|
|
|
}
|
2011-09-26 14:51:15 +02:00
|
|
|
|
2011-12-15 12:25:40 +01:00
|
|
|
throw new WebSocketHandshakeException("Protocol version " + version.toString() + " not supported.");
|
|
|
|
}
|
2011-09-26 14:51:15 +02:00
|
|
|
}
|