private void encodeResponse(IoSessionEx session, HttpResponseMessage httpResponse, ProtocolEncoderOutput out) throws Exception {
boolean isGzipped = HttpUtils.isGzipped(httpResponse);
boolean isChunked = HttpUtils.isChunked(httpResponse);
ByteBuffer nioBuf = allocator.allocate(1024);
IoBufferEx buf = allocator.wrap(nioBuf).setAutoExpander(allocator);
int allocatedPos = buf.position();
encodeResponseLine(httpResponse.getVersion(), httpResponse.getStatus(), httpResponse.getReason(), buf);
encodeHeaders(session, httpResponse, buf);
if (isGzipped) {
buf.put(HttpGzipEncoder.GZIP_START_OF_FRAME_BYTES);
}
HttpContentMessage httpContent = httpResponse.getContent();
if (httpContent != null) {
encodeContent(session, httpContent, buf, isChunked, isGzipped);
}
buf.flip();
buf.position(allocatedPos);
out.write(buf);
}