Skip to content

Commit

Permalink
Release request ByteBuf
Browse files Browse the repository at this point in the history
  • Loading branch information
ar committed Aug 26, 2019
1 parent 103bbc3 commit 6322db9
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions modules/qrest/src/main/java/org/jpos/qrest/SendResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@

package org.jpos.qrest;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.*;
import io.netty.util.ReferenceCountUtil;
import org.jpos.core.Configurable;
import org.jpos.core.Configuration;
import org.jpos.rc.Result;
Expand Down Expand Up @@ -69,16 +68,20 @@ public void abort (long id, Serializable context) {
private void sendResponse (Context ctx, ChannelHandlerContext ch, FullHttpRequest request, FullHttpResponse response) {
boolean keepAlive = HttpUtil.isKeepAlive(request);
HttpHeaders headers = response.headers();
if (keepAlive)
headers.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);

if (contentType != null)
headers.set(HttpHeaderNames.CONTENT_TYPE, contentType);
headers.set(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes());
ChannelFuture cf = ch.writeAndFlush(response);
ctx.log(cf);
if (!keepAlive)
ch.close();
try {
if (keepAlive)
headers.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);

if (contentType != null)
headers.set(HttpHeaderNames.CONTENT_TYPE, contentType);
headers.set(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes());
ChannelFuture cf = ch.writeAndFlush(response);
ctx.log(cf);
if (!keepAlive)
ch.close();
} finally {
ReferenceCountUtil.release(request);
}
}

private FullHttpResponse error (HttpResponseStatus rc) {
Expand Down

0 comments on commit 6322db9

Please sign in to comment.