Stop decoding after protocol upgrade / Do not use singleDecode option

This commit is contained in:
Trustin Lee 2013-12-18 20:29:13 +09:00
parent fa336db891
commit d35c2010c4
2 changed files with 20 additions and 5 deletions

View File

@ -126,7 +126,8 @@ public abstract class HttpObjectDecoder extends ReplayingDecoder<HttpObjectDecod
READ_CHUNKED_CONTENT,
READ_CHUNK_DELIMITER,
READ_CHUNK_FOOTER,
BAD_MESSAGE
BAD_MESSAGE,
UPGRADED
}
/**
@ -354,6 +355,12 @@ public abstract class HttpObjectDecoder extends ReplayingDecoder<HttpObjectDecod
case BAD_MESSAGE: {
// Keep discarding until disconnection.
buffer.skipBytes(actualReadableBytes());
break;
}
case UPGRADED: {
// Do not touch anything read - other handler will replace this codec with the upgraded protocol codec to
// take the trafic over.
break;
}
}
}
@ -410,7 +417,17 @@ public abstract class HttpObjectDecoder extends ReplayingDecoder<HttpObjectDecod
}
private void reset() {
message = null;
HttpMessage message = this.message;
this.message = null;
if (!isDecodingRequest()) {
HttpResponse res = (HttpResponse) message;
if (res != null && res.getStatus().code() == 101) {
checkpoint(State.UPGRADED);
return;
}
}
checkpoint(State.SKIP_CONTROL_CHARS);
}

View File

@ -157,10 +157,8 @@ public abstract class WebSocketClientHandshaker {
"a HttpResponseDecoder or HttpClientCodec"));
return promise;
}
codec.setSingleDecode(true);
} else {
decoder.setSingleDecode(true);
}
channel.writeAndFlush(request).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {