@@ -115,13 +115,23 @@ public class Draft_6455 extends Draft {
115115 /**
116116 * Attribute for the used extension in this draft
117117 */
118- private IExtension extension = new DefaultExtension ();
118+ private IExtension negotiatedExtension = new DefaultExtension ();
119+
120+ /**
121+ * Attribute for the default extension
122+ */
123+ private IExtension defaultExtension = new DefaultExtension ();
119124
120125 /**
121126 * Attribute for all available extension in this draft
122127 */
123128 private List <IExtension > knownExtensions ;
124129
130+ /**
131+ * Current active extension used to decode messages
132+ */
133+ private IExtension currentDecodingExtension ;
134+
125135 /**
126136 * Attribute for the used protocol in this draft
127137 */
@@ -241,10 +251,11 @@ public Draft_6455(List<IExtension> inputExtensions, List<IProtocol> inputProtoco
241251 knownExtensions .addAll (inputExtensions );
242252 //We always add the DefaultExtension to implement the normal RFC 6455 specification
243253 if (!hasDefault ) {
244- knownExtensions .add (this .knownExtensions .size (), extension );
254+ knownExtensions .add (this .knownExtensions .size (), negotiatedExtension );
245255 }
246256 knownProtocols .addAll (inputProtocols );
247257 maxFrameSize = inputMaxFrameSize ;
258+ currentDecodingExtension = null ;
248259 }
249260
250261 @ Override
@@ -259,9 +270,9 @@ public HandshakeState acceptHandshakeAsServer(ClientHandshake handshakedata)
259270 String requestedExtension = handshakedata .getFieldValue (SEC_WEB_SOCKET_EXTENSIONS );
260271 for (IExtension knownExtension : knownExtensions ) {
261272 if (knownExtension .acceptProvidedExtensionAsServer (requestedExtension )) {
262- extension = knownExtension ;
273+ negotiatedExtension = knownExtension ;
263274 extensionState = HandshakeState .MATCHED ;
264- log .trace ("acceptHandshakeAsServer - Matching extension found: {}" , extension );
275+ log .trace ("acceptHandshakeAsServer - Matching extension found: {}" , negotiatedExtension );
265276 break ;
266277 }
267278 }
@@ -316,9 +327,9 @@ public HandshakeState acceptHandshakeAsClient(ClientHandshake request, ServerHan
316327 String requestedExtension = response .getFieldValue (SEC_WEB_SOCKET_EXTENSIONS );
317328 for (IExtension knownExtension : knownExtensions ) {
318329 if (knownExtension .acceptProvidedExtensionAsClient (requestedExtension )) {
319- extension = knownExtension ;
330+ negotiatedExtension = knownExtension ;
320331 extensionState = HandshakeState .MATCHED ;
321- log .trace ("acceptHandshakeAsClient - Matching extension found: {}" , extension );
332+ log .trace ("acceptHandshakeAsClient - Matching extension found: {}" , negotiatedExtension );
322333 break ;
323334 }
324335 }
@@ -337,7 +348,7 @@ public HandshakeState acceptHandshakeAsClient(ClientHandshake request, ServerHan
337348 * @return the extension which is used or null, if handshake is not yet done
338349 */
339350 public IExtension getExtension () {
340- return extension ;
351+ return negotiatedExtension ;
341352 }
342353
343354 /**
@@ -562,8 +573,20 @@ private Framedata translateSingleFrame(ByteBuffer buffer)
562573 frame .setRSV3 (rsv3 );
563574 payload .flip ();
564575 frame .setPayload (payload );
565- getExtension ().isFrameValid (frame );
566- getExtension ().decodeFrame (frame );
576+ if (frame .getOpcode () != Opcode .CONTINUOUS ) {
577+ // Prioritize the negotiated extension
578+ if (frame .isRSV1 () ||frame .isRSV2 () || frame .isRSV3 ()) {
579+ currentDecodingExtension = getExtension ();
580+ } else {
581+ // No encoded message, so we can use the default one
582+ currentDecodingExtension = defaultExtension ;
583+ }
584+ }
585+ if (currentDecodingExtension == null ) {
586+ currentDecodingExtension = defaultExtension ;
587+ }
588+ currentDecodingExtension .isFrameValid (frame );
589+ currentDecodingExtension .decodeFrame (frame );
567590 if (log .isTraceEnabled ()) {
568591 log .trace ("afterDecoding({}): {}" , frame .getPayloadData ().remaining (),
569592 (frame .getPayloadData ().remaining () > 1000 ? "too big to display"
@@ -780,10 +803,10 @@ public List<Framedata> createFrames(String text, boolean mask) {
780803 @ Override
781804 public void reset () {
782805 incompleteframe = null ;
783- if (extension != null ) {
784- extension .reset ();
806+ if (negotiatedExtension != null ) {
807+ negotiatedExtension .reset ();
785808 }
786- extension = new DefaultExtension ();
809+ negotiatedExtension = new DefaultExtension ();
787810 protocol = null ;
788811 }
789812
@@ -1116,15 +1139,15 @@ public boolean equals(Object o) {
11161139 if (maxFrameSize != that .getMaxFrameSize ()) {
11171140 return false ;
11181141 }
1119- if (extension != null ? !extension .equals (that .getExtension ()) : that .getExtension () != null ) {
1142+ if (negotiatedExtension != null ? !negotiatedExtension .equals (that .getExtension ()) : that .getExtension () != null ) {
11201143 return false ;
11211144 }
11221145 return protocol != null ? protocol .equals (that .getProtocol ()) : that .getProtocol () == null ;
11231146 }
11241147
11251148 @ Override
11261149 public int hashCode () {
1127- int result = extension != null ? extension .hashCode () : 0 ;
1150+ int result = negotiatedExtension != null ? negotiatedExtension .hashCode () : 0 ;
11281151 result = 31 * result + (protocol != null ? protocol .hashCode () : 0 );
11291152 result = 31 * result + (maxFrameSize ^ (maxFrameSize >>> 32 ));
11301153 return result ;
0 commit comments