Merged branch 'jetty-9.3.x' into 'jetty-9.4.x'.

This commit is contained in:
Simone Bordet 2016-10-06 16:33:58 +02:00
commit f2061cbe60
4 changed files with 70 additions and 36 deletions

View File

@ -37,6 +37,7 @@ import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.CountingCallback;
import org.eclipse.jetty.util.component.Destroyable;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@ -470,6 +471,7 @@ public abstract class HttpReceiver
*/
protected void reset()
{
destroyDecoder(decoder);
decoder = null;
}
@ -482,9 +484,18 @@ public abstract class HttpReceiver
*/
protected void dispose()
{
destroyDecoder(decoder);
decoder = null;
}
private static void destroyDecoder(ContentDecoder decoder)
{
if (decoder instanceof Destroyable)
{
((Destroyable)decoder).destroy();
}
}
public boolean abort(HttpExchange exchange, Throwable failure)
{
// Update the state to avoid more response processing.

View File

@ -25,6 +25,7 @@ import java.util.zip.ZipException;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.component.Destroyable;
/**
* Decoder for the "gzip" encoding.
@ -32,7 +33,7 @@ import org.eclipse.jetty.util.BufferUtil;
* A decoder that inflates gzip compressed data that has been
* optimized for async usage with minimal data copies.
*/
public class GZIPContentDecoder
public class GZIPContentDecoder implements Destroyable
{
private final Inflater _inflater = new Inflater(true);
private final ByteBufferPool _pool;
@ -383,6 +384,12 @@ public class GZIPContentDecoder
_flags = 0;
}
@Override
public void destroy()
{
_inflater.end();
}
public boolean isFinished()
{
return _state == State.INITIAL;

View File

@ -37,6 +37,7 @@ import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.io.RuntimeIOException;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.component.Destroyable;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@ -80,7 +81,7 @@ public class HttpInput extends ServletInputStream implements Runnable
* {@link #readFrom(Content)} and then passes any {@link Content} returned
* to the next {@link Interceptor}.
*/
public static class ChainedInterceptor implements Interceptor
public static class ChainedInterceptor implements Interceptor, Destroyable
{
private final Interceptor _prev;
private final Interceptor _next;
@ -106,8 +107,16 @@ public class HttpInput extends ServletInputStream implements Runnable
{
return getNext().readFrom(getPrev().readFrom(content));
}
@Override
public void destroy()
{
if (_prev instanceof Destroyable)
((Destroyable)_prev).destroy();
if (_next instanceof Destroyable)
((Destroyable)_next).destroy();
}
}
private final static Logger LOG = Log.getLogger(HttpInput.class);
private final static Content EOF_CONTENT = new EofContent("EOF");
@ -155,6 +164,8 @@ public class HttpInput extends ServletInputStream implements Runnable
_contentConsumed = 0;
_firstByteTimeStamp = -1;
_blockUntil = 0;
if (_interceptor instanceof Destroyable)
((Destroyable)_interceptor).destroy();
_interceptor = null;
}
}

View File

@ -24,18 +24,51 @@ import org.eclipse.jetty.http.GZIPContentDecoder;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.server.HttpInput;
import org.eclipse.jetty.server.HttpInput.Content;
import org.eclipse.jetty.util.component.Destroyable;
/**
* A HttpInput Interceptor that inflates GZIP encoded request content.
*
*/
public class GzipHttpInputInterceptor implements HttpInput.Interceptor
public class GzipHttpInputInterceptor implements HttpInput.Interceptor, Destroyable
{
class Decoder extends GZIPContentDecoder
private final Decoder _decoder;
private ByteBuffer _chunk;
public GzipHttpInputInterceptor(ByteBufferPool pool, int bufferSize)
{
public Decoder(ByteBufferPool pool, int bufferSize)
_decoder = new Decoder(pool, bufferSize);
}
@Override
public Content readFrom(Content content)
{
_decoder.decodeChunks(content.getByteBuffer());
final ByteBuffer chunk = _chunk;
if (chunk == null)
return null;
return new Content(chunk)
{
super(pool,bufferSize);
@Override
public void succeeded()
{
_decoder.release(chunk);
}
};
}
@Override
public void destroy()
{
_decoder.destroy();
}
private class Decoder extends GZIPContentDecoder
{
private Decoder(ByteBufferPool pool, int bufferSize)
{
super(pool, bufferSize);
}
@Override
@ -52,32 +85,4 @@ public class GzipHttpInputInterceptor implements HttpInput.Interceptor
super.decodeChunks(compressed);
}
}
private final Decoder _decoder;
private ByteBuffer _chunk;
public GzipHttpInputInterceptor(ByteBufferPool pool, int bufferSize)
{
_decoder = new Decoder(pool,bufferSize);
}
@Override
public Content readFrom(Content content)
{
_decoder.decodeChunks(content.getByteBuffer());
final ByteBuffer chunk = _chunk;
if (chunk==null)
return null;
return new Content(chunk)
{
@Override
public void succeeded()
{
_decoder.release(chunk);
}
};
}
}