diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectEncoder.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectEncoder.java index e6bb50be7e..1affe26155 100755 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectEncoder.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpObjectEncoder.java @@ -70,7 +70,7 @@ public abstract class HttpObjectEncoder extends MessageTo buf = ctx.alloc().buffer(); // Encode the message. encodeInitialLine(buf, m); - m.headers().forEachEntry(new HttpHeadersEncoder(buf)); + encodeHeaders(m.headers(), buf); buf.writeBytes(CRLF); state = HttpHeaderUtil.isTransferEncodingChunked(m) ? ST_CONTENT_CHUNK : ST_CONTENT_NON_CHUNK; } @@ -133,6 +133,13 @@ public abstract class HttpObjectEncoder extends MessageTo } } + /** + * Encode the {@link HttpHeaders} into a {@link ByteBuf}. + */ + protected void encodeHeaders(HttpHeaders headers, ByteBuf buf) throws Exception { + headers.forEachEntry(new HttpHeadersEncoder(buf)); + } + private void encodeChunkedContent(ChannelHandlerContext ctx, Object msg, long contentLength, List out) { if (contentLength > 0) { byte[] length = Long.toHexString(contentLength).getBytes(CharsetUtil.US_ASCII); @@ -152,7 +159,7 @@ public abstract class HttpObjectEncoder extends MessageTo ByteBuf buf = ctx.alloc().buffer(); buf.writeBytes(ZERO_CRLF); try { - headers.forEachEntry(new HttpHeadersEncoder(buf)); + encodeHeaders(headers, buf); } catch (Exception ex) { buf.release(); PlatformDependent.throwException(ex);