@@ -115,13 +115,23 @@ public class Draft_6455 extends Draft {
115
115
/**
116
116
* Attribute for the used extension in this draft
117
117
*/
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 ();
119
124
120
125
/**
121
126
* Attribute for all available extension in this draft
122
127
*/
123
128
private List <IExtension > knownExtensions ;
124
129
130
+ /**
131
+ * Current active extension used to decode messages
132
+ */
133
+ private IExtension currentDecodingExtension ;
134
+
125
135
/**
126
136
* Attribute for the used protocol in this draft
127
137
*/
@@ -241,10 +251,11 @@ public Draft_6455(List<IExtension> inputExtensions, List<IProtocol> inputProtoco
241
251
knownExtensions .addAll (inputExtensions );
242
252
//We always add the DefaultExtension to implement the normal RFC 6455 specification
243
253
if (!hasDefault ) {
244
- knownExtensions .add (this .knownExtensions .size (), extension );
254
+ knownExtensions .add (this .knownExtensions .size (), negotiatedExtension );
245
255
}
246
256
knownProtocols .addAll (inputProtocols );
247
257
maxFrameSize = inputMaxFrameSize ;
258
+ currentDecodingExtension = null ;
248
259
}
249
260
250
261
@ Override
@@ -259,9 +270,9 @@ public HandshakeState acceptHandshakeAsServer(ClientHandshake handshakedata)
259
270
String requestedExtension = handshakedata .getFieldValue (SEC_WEB_SOCKET_EXTENSIONS );
260
271
for (IExtension knownExtension : knownExtensions ) {
261
272
if (knownExtension .acceptProvidedExtensionAsServer (requestedExtension )) {
262
- extension = knownExtension ;
273
+ negotiatedExtension = knownExtension ;
263
274
extensionState = HandshakeState .MATCHED ;
264
- log .trace ("acceptHandshakeAsServer - Matching extension found: {}" , extension );
275
+ log .trace ("acceptHandshakeAsServer - Matching extension found: {}" , negotiatedExtension );
265
276
break ;
266
277
}
267
278
}
@@ -316,9 +327,9 @@ public HandshakeState acceptHandshakeAsClient(ClientHandshake request, ServerHan
316
327
String requestedExtension = response .getFieldValue (SEC_WEB_SOCKET_EXTENSIONS );
317
328
for (IExtension knownExtension : knownExtensions ) {
318
329
if (knownExtension .acceptProvidedExtensionAsClient (requestedExtension )) {
319
- extension = knownExtension ;
330
+ negotiatedExtension = knownExtension ;
320
331
extensionState = HandshakeState .MATCHED ;
321
- log .trace ("acceptHandshakeAsClient - Matching extension found: {}" , extension );
332
+ log .trace ("acceptHandshakeAsClient - Matching extension found: {}" , negotiatedExtension );
322
333
break ;
323
334
}
324
335
}
@@ -337,7 +348,7 @@ public HandshakeState acceptHandshakeAsClient(ClientHandshake request, ServerHan
337
348
* @return the extension which is used or null, if handshake is not yet done
338
349
*/
339
350
public IExtension getExtension () {
340
- return extension ;
351
+ return negotiatedExtension ;
341
352
}
342
353
343
354
/**
@@ -562,8 +573,20 @@ private Framedata translateSingleFrame(ByteBuffer buffer)
562
573
frame .setRSV3 (rsv3 );
563
574
payload .flip ();
564
575
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 );
567
590
if (log .isTraceEnabled ()) {
568
591
log .trace ("afterDecoding({}): {}" , frame .getPayloadData ().remaining (),
569
592
(frame .getPayloadData ().remaining () > 1000 ? "too big to display"
@@ -780,10 +803,10 @@ public List<Framedata> createFrames(String text, boolean mask) {
780
803
@ Override
781
804
public void reset () {
782
805
incompleteframe = null ;
783
- if (extension != null ) {
784
- extension .reset ();
806
+ if (negotiatedExtension != null ) {
807
+ negotiatedExtension .reset ();
785
808
}
786
- extension = new DefaultExtension ();
809
+ negotiatedExtension = new DefaultExtension ();
787
810
protocol = null ;
788
811
}
789
812
@@ -1116,15 +1139,15 @@ public boolean equals(Object o) {
1116
1139
if (maxFrameSize != that .getMaxFrameSize ()) {
1117
1140
return false ;
1118
1141
}
1119
- if (extension != null ? !extension .equals (that .getExtension ()) : that .getExtension () != null ) {
1142
+ if (negotiatedExtension != null ? !negotiatedExtension .equals (that .getExtension ()) : that .getExtension () != null ) {
1120
1143
return false ;
1121
1144
}
1122
1145
return protocol != null ? protocol .equals (that .getProtocol ()) : that .getProtocol () == null ;
1123
1146
}
1124
1147
1125
1148
@ Override
1126
1149
public int hashCode () {
1127
- int result = extension != null ? extension .hashCode () : 0 ;
1150
+ int result = negotiatedExtension != null ? negotiatedExtension .hashCode () : 0 ;
1128
1151
result = 31 * result + (protocol != null ? protocol .hashCode () : 0 );
1129
1152
result = 31 * result + (maxFrameSize ^ (maxFrameSize >>> 32 ));
1130
1153
return result ;
0 commit comments