BytesFullResponseHandler should only consume readableBytes of ChannelBuffer (#6270)

This commit is contained in:
Dayue Gao 2018-08-31 11:22:08 +08:00 committed by Jonathan Wei
parent 9b04846e6b
commit 951b36e2bc
1 changed files with 10 additions and 2 deletions

View File

@ -22,6 +22,7 @@ package org.apache.druid.security.basic.authentication;
import org.apache.druid.java.util.http.client.response.ClientResponse;
import org.apache.druid.java.util.http.client.response.FullResponseHolder;
import org.apache.druid.java.util.http.client.response.HttpResponseHandler;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.handler.codec.http.HttpChunk;
import org.jboss.netty.handler.codec.http.HttpResponse;
@ -36,7 +37,7 @@ public class BytesFullResponseHandler implements HttpResponseHandler<FullRespons
null
);
holder.addChunk(response.getContent().array());
holder.addChunk(getContentBytes(response.getContent()));
return ClientResponse.unfinished(
holder
@ -55,7 +56,7 @@ public class BytesFullResponseHandler implements HttpResponseHandler<FullRespons
return ClientResponse.finished(null);
}
holder.addChunk(chunk.getContent().array());
holder.addChunk(getContentBytes(chunk.getContent()));
return response;
}
@ -72,4 +73,11 @@ public class BytesFullResponseHandler implements HttpResponseHandler<FullRespons
{
// Its safe to Ignore as the ClientResponse returned in handleChunk were unfinished
}
private byte[] getContentBytes(ChannelBuffer content)
{
byte[] contentBytes = new byte[content.readableBytes()];
content.readBytes(contentBytes);
return contentBytes;
}
}