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 committed by Norman Maurer
parent 0f76b3c357
commit e9f09ea9f5
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_CHUNKED_CONTENT,
READ_CHUNK_DELIMITER, READ_CHUNK_DELIMITER,
READ_CHUNK_FOOTER, READ_CHUNK_FOOTER,
BAD_MESSAGE BAD_MESSAGE,
UPGRADED
} }
/** /**
@ -354,6 +355,12 @@ public abstract class HttpObjectDecoder extends ReplayingDecoder<HttpObjectDecod
case BAD_MESSAGE: { case BAD_MESSAGE: {
// Keep discarding until disconnection. // Keep discarding until disconnection.
buffer.skipBytes(actualReadableBytes()); 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() { 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); checkpoint(State.SKIP_CONTROL_CHARS);
} }

View File

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