@@ -53,12 +53,6 @@ final class WebSocketProtocol extends Protocol {
53
53
54
54
private static final Logger LOGGER = LoggerFactory .getLogger (WebSocketProtocol .class );
55
55
56
- private static final byte OPCODE_TEXT = 0x1 ;
57
- private static final byte OPCODE_BINARY = 0x2 ;
58
- private static final byte OPCODE_UNKNOWN = -1 ;
59
- // FIXME How is this threadsafe? WebSocketProtocol instance is a member of NettyChannelHandler which is @Shareable
60
- protected byte pendingOpcode = OPCODE_UNKNOWN ;
61
-
62
56
public WebSocketProtocol (Channels channels , AsyncHttpClientConfig config , NettyAsyncHttpProviderConfig nettyConfig , NettyRequestSender requestSender ) {
63
57
super (channels , config , nettyConfig , requestSender );
64
58
}
@@ -134,19 +128,15 @@ public void handle(ChannelHandlerContext ctx, NettyResponseFuture future, Object
134
128
CloseWebSocketFrame closeFrame = CloseWebSocketFrame .class .cast (frame );
135
129
webSocket .onClose (closeFrame .statusCode (), closeFrame .reasonText ());
136
130
} else {
137
- if (frame instanceof TextWebSocketFrame ) {
138
- pendingOpcode = OPCODE_TEXT ;
139
- } else if (frame instanceof BinaryWebSocketFrame ) {
140
- pendingOpcode = OPCODE_BINARY ;
141
- }
131
+ boolean binaryFrame = frame instanceof BinaryWebSocketFrame ;
142
132
143
133
ByteBuf buf = frame .content ();
144
134
if (buf != null && buf .readableBytes () > 0 ) {
145
135
try {
146
136
ResponseBodyPart rp = nettyConfig .getBodyPartFactory ().newResponseBodyPart (buf , frame .isFinalFragment ());
147
137
h .onBodyPartReceived (rp );
148
138
149
- if (pendingOpcode == OPCODE_BINARY ) {
139
+ if (binaryFrame ) {
150
140
webSocket .onBinaryFragment (rp .getBodyPartBytes (), frame .isFinalFragment ());
151
141
} else {
152
142
webSocket .onTextFragment (buf .toString (Constants .UTF8 ), frame .isFinalFragment ());
0 commit comments