Issue #1309 Client GZIPContentDecoder uses client ByteBufferPool

Previously the GZIPContentDecoder would allocate a new buffer for
each gzip encoded response.

Signed-off-by: Carter Kozak <c4kofony@gmail.com>
This commit is contained in:
Carter Kozak 2017-02-05 11:28:26 -05:00
parent 6509bc584b
commit 1a2bb90465
2 changed files with 25 additions and 5 deletions

View File

@ -18,6 +18,7 @@
package org.eclipse.jetty.client;
import org.eclipse.jetty.io.ByteBufferPool;
/**
* {@link ContentDecoder} for the "gzip" encoding.
@ -26,14 +27,21 @@ package org.eclipse.jetty.client;
public class GZIPContentDecoder extends org.eclipse.jetty.http.GZIPContentDecoder implements ContentDecoder
{
private static final int DEFAULT_BUFFER_SIZE = 2048;
public GZIPContentDecoder()
{
this(2048);
this(DEFAULT_BUFFER_SIZE);
}
public GZIPContentDecoder(int bufferSize)
{
super(null,bufferSize);
this(null,bufferSize);
}
public GZIPContentDecoder(ByteBufferPool byteBufferPool, int bufferSize)
{
super(byteBufferPool, bufferSize);
}
/**
@ -42,22 +50,34 @@ public class GZIPContentDecoder extends org.eclipse.jetty.http.GZIPContentDecode
public static class Factory extends ContentDecoder.Factory
{
private final int bufferSize;
private final ByteBufferPool byteBufferPool;
public Factory()
{
this(2048);
this(DEFAULT_BUFFER_SIZE);
}
public Factory(int bufferSize)
{
this(null, bufferSize);
}
public Factory(ByteBufferPool byteBufferPool)
{
this(byteBufferPool, DEFAULT_BUFFER_SIZE);
}
public Factory(ByteBufferPool byteBufferPool, int bufferSize)
{
super("gzip");
this.byteBufferPool = byteBufferPool;
this.bufferSize = bufferSize;
}
@Override
public ContentDecoder newContentDecoder()
{
return new GZIPContentDecoder(bufferSize);
return new GZIPContentDecoder(byteBufferPool, bufferSize);
}
}
}

View File

@ -224,7 +224,7 @@ public class HttpClient extends ContainerLifeCycle
handlers.put(new WWWAuthenticationProtocolHandler(this));
handlers.put(new ProxyAuthenticationProtocolHandler(this));
decoderFactories.add(new GZIPContentDecoder.Factory());
decoderFactories.add(new GZIPContentDecoder.Factory(byteBufferPool));
cookieManager = newCookieManager();
cookieStore = cookieManager.getCookieStore();