1 /* 2 * Copyright 2012 The Netty Project 3 * 4 * The Netty Project licenses this file to you under the Apache License, 5 * version 2.0 (the "License"); you may not use this file except in compliance 6 * with the License. You may obtain a copy of the License at: 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations 14 * under the License. 15 */ 16 package io.netty.handler.codec.http.websocketx; 17 18 import io.netty.util.AsciiString; 19 import io.netty.util.internal.StringUtil; 20 21 /** 22 * <p> 23 * Versions of the web socket specification. 24 * </p> 25 * <p> 26 * A specification is tied to one wire protocol version but a protocol version may have use by more than 1 version of 27 * the specification. 28 * </p> 29 */ 30 public enum WebSocketVersion { 31 UNKNOWN(AsciiString.cached(StringUtil.EMPTY_STRING)), 32 33 /** 34 * <a href= "https://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-00" 35 * >draft-ietf-hybi-thewebsocketprotocol- 00</a>. 36 */ 37 V00(AsciiString.cached("0")), 38 39 /** 40 * <a href= "https://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-07" 41 * >draft-ietf-hybi-thewebsocketprotocol- 07</a> 42 */ 43 V07(AsciiString.cached("7")), 44 45 /** 46 * <a href= "https://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10" 47 * >draft-ietf-hybi-thewebsocketprotocol- 10</a> 48 */ 49 V08(AsciiString.cached("8")), 50 51 /** 52 * <a href="https://tools.ietf.org/html/rfc6455 ">RFC 6455</a>. This was originally <a href= 53 * "https://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17" >draft-ietf-hybi-thewebsocketprotocol- 54 * 17</a> 55 */ 56 V13(AsciiString.cached("13")); 57 58 private final AsciiString headerValue; 59 60 WebSocketVersion(AsciiString headerValue) { 61 this.headerValue = headerValue; 62 } 63 /** 64 * @return Value for HTTP Header 'Sec-WebSocket-Version' 65 */ 66 public String toHttpHeaderValue() { 67 return toAsciiString().toString(); 68 } 69 70 AsciiString toAsciiString() { 71 if (this == UNKNOWN) { 72 // Let's special case this to preserve behaviour 73 throw new IllegalStateException("Unknown web socket version: " + this); 74 } 75 return headerValue; 76 } 77 }