Skip to content

Commit 9e67cce

Browse files
committed
Use BufUtil.retain() where possible
1 parent 6568cbf commit 9e67cce

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

codec-http/src/main/java/io/netty/handler/codec/http/HttpContentEncoder.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616
package io.netty.handler.codec.http;
1717

18+
import io.netty.buffer.BufUtil;
1819
import io.netty.buffer.ByteBuf;
1920
import io.netty.buffer.ByteBufHolder;
20-
import io.netty.buffer.ReferenceCounted;
2121
import io.netty.buffer.Unpooled;
2222
import io.netty.channel.ChannelHandlerContext;
2323
import io.netty.channel.embedded.EmbeddedByteChannel;
@@ -62,12 +62,8 @@ protected Object decode(ChannelHandlerContext ctx, HttpMessage msg)
6262
if (acceptedEncoding == null) {
6363
acceptedEncoding = HttpHeaders.Values.IDENTITY;
6464
}
65-
boolean offered = acceptEncodingQueue.offer(acceptedEncoding);
66-
assert offered;
67-
if (msg instanceof ReferenceCounted) {
68-
// need to call retain to not free it
69-
((ReferenceCounted) msg).retain();
70-
}
65+
acceptEncodingQueue.add(acceptedEncoding);
66+
BufUtil.retain(msg);
7167
return msg;
7268
}
7369

@@ -76,10 +72,7 @@ protected Object encode(ChannelHandlerContext ctx, HttpObject msg)
7672
throws Exception {
7773
if (msg instanceof HttpResponse && ((HttpResponse) msg).getStatus().code() == 100) {
7874
// 100-continue response must be passed through.
79-
if (msg instanceof ReferenceCounted) {
80-
// need to call retain to not free it
81-
((ReferenceCounted) msg).retain();
82-
}
75+
BufUtil.retain(msg);
8376
return msg;
8477
}
8578

0 commit comments

Comments
 (0)