updates from review
introduce default buffer size constant
This commit is contained in:
parent
e699583c04
commit
2ba2250ac8
|
@ -20,13 +20,14 @@ import org.eclipse.jetty.http.HttpField;
|
||||||
import org.eclipse.jetty.http.HttpHeader;
|
import org.eclipse.jetty.http.HttpHeader;
|
||||||
import org.eclipse.jetty.io.ByteBufferPool;
|
import org.eclipse.jetty.io.ByteBufferPool;
|
||||||
import org.eclipse.jetty.io.RetainableByteBuffer;
|
import org.eclipse.jetty.io.RetainableByteBuffer;
|
||||||
|
import org.eclipse.jetty.util.IO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link ContentDecoder} for the "gzip" encoding.
|
* {@link ContentDecoder} for the "gzip" encoding.
|
||||||
*/
|
*/
|
||||||
public class GZIPContentDecoder extends org.eclipse.jetty.http.GZIPContentDecoder implements ContentDecoder
|
public class GZIPContentDecoder extends org.eclipse.jetty.http.GZIPContentDecoder implements ContentDecoder
|
||||||
{
|
{
|
||||||
public static final int DEFAULT_BUFFER_SIZE = 8192;
|
public static final int DEFAULT_BUFFER_SIZE = IO.DEFAULT_BUFFER_SIZE;
|
||||||
|
|
||||||
private long decodedLength;
|
private long decodedLength;
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.BufferUtil;
|
import org.eclipse.jetty.util.BufferUtil;
|
||||||
|
import org.eclipse.jetty.util.IO;
|
||||||
import org.eclipse.jetty.util.StringUtil;
|
import org.eclipse.jetty.util.StringUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,7 +63,7 @@ public class HttpTester
|
||||||
|
|
||||||
public Input()
|
public Input()
|
||||||
{
|
{
|
||||||
this(BufferUtil.allocate(8192));
|
this(BufferUtil.allocate(IO.DEFAULT_BUFFER_SIZE));
|
||||||
}
|
}
|
||||||
|
|
||||||
Input(ByteBuffer buffer)
|
Input(ByteBuffer buffer)
|
||||||
|
@ -477,7 +478,7 @@ public class HttpTester
|
||||||
switch (result)
|
switch (result)
|
||||||
{
|
{
|
||||||
case NEED_HEADER:
|
case NEED_HEADER:
|
||||||
header = BufferUtil.allocate(8192);
|
header = BufferUtil.allocate(IO.DEFAULT_BUFFER_SIZE);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case HEADER_OVERFLOW:
|
case HEADER_OVERFLOW:
|
||||||
|
@ -491,7 +492,7 @@ public class HttpTester
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case NEED_CHUNK_TRAILER:
|
case NEED_CHUNK_TRAILER:
|
||||||
chunk = BufferUtil.allocate(8192);
|
chunk = BufferUtil.allocate(IO.DEFAULT_BUFFER_SIZE);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case NEED_INFO:
|
case NEED_INFO:
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.eclipse.jetty.io.ClientConnectionFactory;
|
||||||
import org.eclipse.jetty.io.ClientConnector;
|
import org.eclipse.jetty.io.ClientConnector;
|
||||||
import org.eclipse.jetty.io.Transport;
|
import org.eclipse.jetty.io.Transport;
|
||||||
import org.eclipse.jetty.io.ssl.SslClientConnectionFactory;
|
import org.eclipse.jetty.io.ssl.SslClientConnectionFactory;
|
||||||
|
import org.eclipse.jetty.util.IO;
|
||||||
import org.eclipse.jetty.util.Promise;
|
import org.eclipse.jetty.util.Promise;
|
||||||
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||||
|
@ -102,7 +103,7 @@ import org.eclipse.jetty.util.thread.Scheduler;
|
||||||
public class HTTP2Client extends ContainerLifeCycle
|
public class HTTP2Client extends ContainerLifeCycle
|
||||||
{
|
{
|
||||||
private final ClientConnector connector;
|
private final ClientConnector connector;
|
||||||
private int inputBufferSize = 8192;
|
private int inputBufferSize = IO.DEFAULT_BUFFER_SIZE;
|
||||||
private List<String> protocols = List.of("h2");
|
private List<String> protocols = List.of("h2");
|
||||||
private int initialSessionRecvWindow = 16 * 1024 * 1024;
|
private int initialSessionRecvWindow = 16 * 1024 * 1024;
|
||||||
private int initialStreamRecvWindow = 8 * 1024 * 1024;
|
private int initialStreamRecvWindow = 8 * 1024 * 1024;
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.http3;
|
package org.eclipse.jetty.http3;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.util.IO;
|
||||||
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||||
|
|
||||||
|
@ -186,7 +187,7 @@ public class HTTP3Configuration
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Sets max request headers size.</p>
|
* <p>Sets max request headers size.</p>
|
||||||
* <p>The default value is {@code 8192} bytes.</p>
|
* <p>The default value is {@link IO#DEFAULT_BUFFER_SIZE} bytes.</p>
|
||||||
* <p>This value is configured in the server-side QPACK decoder, and
|
* <p>This value is configured in the server-side QPACK decoder, and
|
||||||
* then communicated to the client-side QPACK encoder via the SETTINGS
|
* then communicated to the client-side QPACK encoder via the SETTINGS
|
||||||
* frame.</p>
|
* frame.</p>
|
||||||
|
@ -208,7 +209,7 @@ public class HTTP3Configuration
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Sets max response headers size.</p>
|
* <p>Sets max response headers size.</p>
|
||||||
* <p>The default value is {@code 8192} bytes.</p>
|
* <p>The default value is {@link IO#DEFAULT_BUFFER_SIZE} bytes.</p>
|
||||||
* <p>This value is configured in the client-side QPACK decoder, and
|
* <p>This value is configured in the client-side QPACK decoder, and
|
||||||
* then communicated to the server-side QPACK encoder via the SETTINGS
|
* then communicated to the server-side QPACK encoder via the SETTINGS
|
||||||
* frame.</p>
|
* frame.</p>
|
||||||
|
|
|
@ -19,6 +19,7 @@ import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.BufferUtil;
|
import org.eclipse.jetty.util.BufferUtil;
|
||||||
|
import org.eclipse.jetty.util.IO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>A pool for {@link RetainableByteBuffer} instances.</p>
|
* <p>A pool for {@link RetainableByteBuffer} instances.</p>
|
||||||
|
@ -136,7 +137,7 @@ public interface ByteBufferPool
|
||||||
{
|
{
|
||||||
super(Objects.requireNonNullElse(wrapped, NON_POOLING));
|
super(Objects.requireNonNullElse(wrapped, NON_POOLING));
|
||||||
_direct = direct;
|
_direct = direct;
|
||||||
_size = size >= 0 ? size : 8192;
|
_size = size >= 0 ? size : IO.DEFAULT_BUFFER_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDirect()
|
public boolean isDirect()
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.util.Objects;
|
||||||
import org.eclipse.jetty.util.Blocker;
|
import org.eclipse.jetty.util.Blocker;
|
||||||
import org.eclipse.jetty.util.BufferUtil;
|
import org.eclipse.jetty.util.BufferUtil;
|
||||||
import org.eclipse.jetty.util.Callback;
|
import org.eclipse.jetty.util.Callback;
|
||||||
|
import org.eclipse.jetty.util.IO;
|
||||||
import org.eclipse.jetty.util.IteratingNestedCallback;
|
import org.eclipse.jetty.util.IteratingNestedCallback;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -1439,7 +1440,7 @@ public interface RetainableByteBuffer extends Retainable
|
||||||
*/
|
*/
|
||||||
public DynamicCapacity(ByteBufferPool pool, boolean direct, long maxSize, int aggregationSize, int minRetainSize)
|
public DynamicCapacity(ByteBufferPool pool, boolean direct, long maxSize, int aggregationSize, int minRetainSize)
|
||||||
{
|
{
|
||||||
this(null, new ByteBufferPool.Sized(pool, direct, maxSize > 0 && maxSize < 8192L ? (int)maxSize : aggregationSize), maxSize, minRetainSize);
|
this(null, new ByteBufferPool.Sized(pool, direct, maxSize > 0 && maxSize < IO.DEFAULT_BUFFER_SIZE ? (int)maxSize : aggregationSize), maxSize, minRetainSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DynamicCapacity(List<RetainableByteBuffer> buffers, ByteBufferPool.Sized pool, long maxSize, int minRetainSize)
|
private DynamicCapacity(List<RetainableByteBuffer> buffers, ByteBufferPool.Sized pool, long maxSize, int minRetainSize)
|
||||||
|
@ -1500,7 +1501,7 @@ public interface RetainableByteBuffer extends Retainable
|
||||||
throw new BufferOverflowException();
|
throw new BufferOverflowException();
|
||||||
|
|
||||||
int length = (int)size;
|
int length = (int)size;
|
||||||
RetainableByteBuffer combined = _pool.acquire(length, _pool.isDirect());
|
RetainableByteBuffer combined = _pool.acquire(length);
|
||||||
ByteBuffer byteBuffer = combined.getByteBuffer();
|
ByteBuffer byteBuffer = combined.getByteBuffer();
|
||||||
BufferUtil.flipToFill(byteBuffer);
|
BufferUtil.flipToFill(byteBuffer);
|
||||||
for (RetainableByteBuffer buffer : _buffers)
|
for (RetainableByteBuffer buffer : _buffers)
|
||||||
|
@ -2007,7 +2008,7 @@ public interface RetainableByteBuffer extends Retainable
|
||||||
aggregateSize = Math.max(length, aggregateSize);
|
aggregateSize = Math.max(length, aggregateSize);
|
||||||
if (aggregateSize > space)
|
if (aggregateSize > space)
|
||||||
aggregateSize = (int)space;
|
aggregateSize = (int)space;
|
||||||
_aggregate = _pool.acquire(aggregateSize, _pool.isDirect()).asMutable();
|
_aggregate = _pool.acquire(aggregateSize, _pool.isDirect());
|
||||||
checkAggregateLimit(space);
|
checkAggregateLimit(space);
|
||||||
_buffers.add(_aggregate);
|
_buffers.add(_aggregate);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.eclipse.jetty.io.content.AsyncContent;
|
||||||
import org.eclipse.jetty.io.content.BufferedContentSink;
|
import org.eclipse.jetty.io.content.BufferedContentSink;
|
||||||
import org.eclipse.jetty.util.BufferUtil;
|
import org.eclipse.jetty.util.BufferUtil;
|
||||||
import org.eclipse.jetty.util.Callback;
|
import org.eclipse.jetty.util.Callback;
|
||||||
|
import org.eclipse.jetty.util.IO;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -257,7 +258,7 @@ public class BufferedContentSinkTest
|
||||||
|
|
||||||
try (AsyncContent async = new AsyncContent(); )
|
try (AsyncContent async = new AsyncContent(); )
|
||||||
{
|
{
|
||||||
BufferedContentSink buffered = new BufferedContentSink(async, _bufferPool, false, 8192, 8192);
|
BufferedContentSink buffered = new BufferedContentSink(async, _bufferPool, false, IO.DEFAULT_BUFFER_SIZE, IO.DEFAULT_BUFFER_SIZE);
|
||||||
|
|
||||||
Callback.Completable callback = new Callback.Completable();
|
Callback.Completable callback = new Callback.Completable();
|
||||||
buffered.write(false, BufferUtil.toBuffer("Hello "), callback);
|
buffered.write(false, BufferUtil.toBuffer("Hello "), callback);
|
||||||
|
@ -485,7 +486,7 @@ public class BufferedContentSinkTest
|
||||||
try (AsyncContent async = new AsyncContent())
|
try (AsyncContent async = new AsyncContent())
|
||||||
{
|
{
|
||||||
BufferedContentSink buffered = new BufferedContentSink(async, _bufferPool, true, 4096, 4096);
|
BufferedContentSink buffered = new BufferedContentSink(async, _bufferPool, true, 4096, 4096);
|
||||||
AtomicInteger count = new AtomicInteger(8192);
|
AtomicInteger count = new AtomicInteger(IO.DEFAULT_BUFFER_SIZE);
|
||||||
CountDownLatch complete = new CountDownLatch(1);
|
CountDownLatch complete = new CountDownLatch(1);
|
||||||
Callback callback = new Callback()
|
Callback callback = new Callback()
|
||||||
{
|
{
|
||||||
|
@ -571,7 +572,7 @@ public class BufferedContentSinkTest
|
||||||
try (AsyncContent async = new AsyncContent())
|
try (AsyncContent async = new AsyncContent())
|
||||||
{
|
{
|
||||||
BufferedContentSink buffered = new BufferedContentSink(async, _bufferPool, true, 1, 4096);
|
BufferedContentSink buffered = new BufferedContentSink(async, _bufferPool, true, 1, 4096);
|
||||||
AtomicInteger count = new AtomicInteger(8192);
|
AtomicInteger count = new AtomicInteger(IO.DEFAULT_BUFFER_SIZE);
|
||||||
CountDownLatch complete = new CountDownLatch(1);
|
CountDownLatch complete = new CountDownLatch(1);
|
||||||
Callback callback = new Callback()
|
Callback callback = new Callback()
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,6 +19,7 @@ import java.util.List;
|
||||||
import org.eclipse.jetty.io.AbstractConnection;
|
import org.eclipse.jetty.io.AbstractConnection;
|
||||||
import org.eclipse.jetty.io.EndPoint;
|
import org.eclipse.jetty.io.EndPoint;
|
||||||
import org.eclipse.jetty.util.ArrayUtil;
|
import org.eclipse.jetty.util.ArrayUtil;
|
||||||
|
import org.eclipse.jetty.util.IO;
|
||||||
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||||
|
@ -32,7 +33,7 @@ public abstract class AbstractConnectionFactory extends ContainerLifeCycle imple
|
||||||
{
|
{
|
||||||
private final String _protocol;
|
private final String _protocol;
|
||||||
private final List<String> _protocols;
|
private final List<String> _protocols;
|
||||||
private int _inputBufferSize = 8192;
|
private int _inputBufferSize = IO.DEFAULT_BUFFER_SIZE;
|
||||||
|
|
||||||
protected AbstractConnectionFactory(String protocol)
|
protected AbstractConnectionFactory(String protocol)
|
||||||
{
|
{
|
||||||
|
|
|
@ -664,11 +664,11 @@ public class BufferUtil
|
||||||
|
|
||||||
public static void readFrom(InputStream is, int needed, ByteBuffer buffer) throws IOException
|
public static void readFrom(InputStream is, int needed, ByteBuffer buffer) throws IOException
|
||||||
{
|
{
|
||||||
ByteBuffer tmp = allocate(8192);
|
ByteBuffer tmp = allocate(IO.DEFAULT_BUFFER_SIZE);
|
||||||
|
|
||||||
while (needed > 0 && buffer.hasRemaining())
|
while (needed > 0 && buffer.hasRemaining())
|
||||||
{
|
{
|
||||||
int l = is.read(tmp.array(), 0, 8192);
|
int l = is.read(tmp.array(), 0, IO.DEFAULT_BUFFER_SIZE);
|
||||||
if (l < 0)
|
if (l < 0)
|
||||||
break;
|
break;
|
||||||
tmp.position(0);
|
tmp.position(0);
|
||||||
|
@ -688,7 +688,7 @@ public class BufferUtil
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int totalRead = 0;
|
int totalRead = 0;
|
||||||
ByteBuffer tmp = allocate(8192);
|
ByteBuffer tmp = allocate(IO.DEFAULT_BUFFER_SIZE);
|
||||||
while (BufferUtil.space(tmp) > 0 && BufferUtil.space(buffer) > 0)
|
while (BufferUtil.space(tmp) > 0 && BufferUtil.space(buffer) > 0)
|
||||||
{
|
{
|
||||||
int read = is.read(tmp.array(), 0, Math.min(BufferUtil.space(tmp), BufferUtil.space(buffer)));
|
int read = is.read(tmp.array(), 0, Math.min(BufferUtil.space(tmp), BufferUtil.space(buffer)));
|
||||||
|
|
|
@ -57,6 +57,8 @@ public class IO
|
||||||
{
|
{
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(IO.class);
|
private static final Logger LOG = LoggerFactory.getLogger(IO.class);
|
||||||
|
|
||||||
|
public static final int DEFAULT_BUFFER_SIZE = 8192;
|
||||||
|
|
||||||
public static final String
|
public static final String
|
||||||
CRLF = "\r\n";
|
CRLF = "\r\n";
|
||||||
|
|
||||||
|
|
|
@ -606,7 +606,7 @@ public class UrlEncoded
|
||||||
public static void decodeUtf16To(InputStream in, BiConsumer<String, String> adder, int maxLength, int maxKeys) throws IOException
|
public static void decodeUtf16To(InputStream in, BiConsumer<String, String> adder, int maxLength, int maxKeys) throws IOException
|
||||||
{
|
{
|
||||||
InputStreamReader input = new InputStreamReader(in, StandardCharsets.UTF_16);
|
InputStreamReader input = new InputStreamReader(in, StandardCharsets.UTF_16);
|
||||||
StringWriter buf = new StringWriter(8192);
|
StringWriter buf = new StringWriter(IO.DEFAULT_BUFFER_SIZE);
|
||||||
IO.copy(input, buf, maxLength);
|
IO.copy(input, buf, maxLength);
|
||||||
|
|
||||||
decodeTo(buf.getBuffer().toString(), adder, StandardCharsets.UTF_16, maxKeys);
|
decodeTo(buf.getBuffer().toString(), adder, StandardCharsets.UTF_16, maxKeys);
|
||||||
|
|
Loading…
Reference in New Issue