diff --git a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/GZIPContentDecoder.java b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/GZIPContentDecoder.java index cb6213a8405..95ad573cfec 100644 --- a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/GZIPContentDecoder.java +++ b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/GZIPContentDecoder.java @@ -20,13 +20,14 @@ import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.RetainableByteBuffer; +import org.eclipse.jetty.util.IO; /** * {@link ContentDecoder} for the "gzip" encoding. */ 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; diff --git a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpTester.java b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpTester.java index 34297bcd153..a019dfb2cf6 100644 --- a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpTester.java +++ b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpTester.java @@ -23,6 +23,7 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import org.eclipse.jetty.util.BufferUtil; +import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.StringUtil; /** @@ -62,7 +63,7 @@ public class HttpTester public Input() { - this(BufferUtil.allocate(8192)); + this(BufferUtil.allocate(IO.DEFAULT_BUFFER_SIZE)); } Input(ByteBuffer buffer) @@ -477,7 +478,7 @@ public class HttpTester switch (result) { case NEED_HEADER: - header = BufferUtil.allocate(8192); + header = BufferUtil.allocate(IO.DEFAULT_BUFFER_SIZE); continue; case HEADER_OVERFLOW: @@ -491,7 +492,7 @@ public class HttpTester continue; case NEED_CHUNK_TRAILER: - chunk = BufferUtil.allocate(8192); + chunk = BufferUtil.allocate(IO.DEFAULT_BUFFER_SIZE); continue; case NEED_INFO: diff --git a/jetty-core/jetty-http2/jetty-http2-client/src/main/java/org/eclipse/jetty/http2/client/HTTP2Client.java b/jetty-core/jetty-http2/jetty-http2-client/src/main/java/org/eclipse/jetty/http2/client/HTTP2Client.java index b49687bac79..442e6ab52a0 100644 --- a/jetty-core/jetty-http2/jetty-http2-client/src/main/java/org/eclipse/jetty/http2/client/HTTP2Client.java +++ b/jetty-core/jetty-http2/jetty-http2-client/src/main/java/org/eclipse/jetty/http2/client/HTTP2Client.java @@ -34,6 +34,7 @@ import org.eclipse.jetty.io.ClientConnectionFactory; import org.eclipse.jetty.io.ClientConnector; import org.eclipse.jetty.io.Transport; import org.eclipse.jetty.io.ssl.SslClientConnectionFactory; +import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.Promise; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; @@ -102,7 +103,7 @@ import org.eclipse.jetty.util.thread.Scheduler; public class HTTP2Client extends ContainerLifeCycle { private final ClientConnector connector; - private int inputBufferSize = 8192; + private int inputBufferSize = IO.DEFAULT_BUFFER_SIZE; private List protocols = List.of("h2"); private int initialSessionRecvWindow = 16 * 1024 * 1024; private int initialStreamRecvWindow = 8 * 1024 * 1024; diff --git a/jetty-core/jetty-http3/jetty-http3-common/src/main/java/org/eclipse/jetty/http3/HTTP3Configuration.java b/jetty-core/jetty-http3/jetty-http3-common/src/main/java/org/eclipse/jetty/http3/HTTP3Configuration.java index 2d73fdd80ee..4f34e4cd039 100644 --- a/jetty-core/jetty-http3/jetty-http3-common/src/main/java/org/eclipse/jetty/http3/HTTP3Configuration.java +++ b/jetty-core/jetty-http3/jetty-http3-common/src/main/java/org/eclipse/jetty/http3/HTTP3Configuration.java @@ -13,6 +13,7 @@ package org.eclipse.jetty.http3; +import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; @@ -186,7 +187,7 @@ public class HTTP3Configuration /** *

Sets max request headers size.

- *

The default value is {@code 8192} bytes.

+ *

The default value is {@link IO#DEFAULT_BUFFER_SIZE} bytes.

*

This value is configured in the server-side QPACK decoder, and * then communicated to the client-side QPACK encoder via the SETTINGS * frame.

@@ -208,7 +209,7 @@ public class HTTP3Configuration /** *

Sets max response headers size.

- *

The default value is {@code 8192} bytes.

+ *

The default value is {@link IO#DEFAULT_BUFFER_SIZE} bytes.

*

This value is configured in the client-side QPACK decoder, and * then communicated to the server-side QPACK encoder via the SETTINGS * frame.

diff --git a/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ByteBufferPool.java b/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ByteBufferPool.java index bfb14d4d800..6a835fae7bb 100644 --- a/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ByteBufferPool.java +++ b/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ByteBufferPool.java @@ -19,6 +19,7 @@ import java.util.List; import java.util.Objects; import org.eclipse.jetty.util.BufferUtil; +import org.eclipse.jetty.util.IO; /** *

A pool for {@link RetainableByteBuffer} instances.

@@ -136,7 +137,7 @@ public interface ByteBufferPool { super(Objects.requireNonNullElse(wrapped, NON_POOLING)); _direct = direct; - _size = size >= 0 ? size : 8192; + _size = size >= 0 ? size : IO.DEFAULT_BUFFER_SIZE; } public boolean isDirect() diff --git a/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/RetainableByteBuffer.java b/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/RetainableByteBuffer.java index 4a25de06bbd..243975879eb 100644 --- a/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/RetainableByteBuffer.java +++ b/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/RetainableByteBuffer.java @@ -27,6 +27,7 @@ import java.util.Objects; import org.eclipse.jetty.util.Blocker; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; +import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.IteratingNestedCallback; import org.slf4j.Logger; 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) { - 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 buffers, ByteBufferPool.Sized pool, long maxSize, int minRetainSize) @@ -1500,7 +1501,7 @@ public interface RetainableByteBuffer extends Retainable throw new BufferOverflowException(); int length = (int)size; - RetainableByteBuffer combined = _pool.acquire(length, _pool.isDirect()); + RetainableByteBuffer combined = _pool.acquire(length); ByteBuffer byteBuffer = combined.getByteBuffer(); BufferUtil.flipToFill(byteBuffer); for (RetainableByteBuffer buffer : _buffers) @@ -2007,7 +2008,7 @@ public interface RetainableByteBuffer extends Retainable aggregateSize = Math.max(length, aggregateSize); if (aggregateSize > space) aggregateSize = (int)space; - _aggregate = _pool.acquire(aggregateSize, _pool.isDirect()).asMutable(); + _aggregate = _pool.acquire(aggregateSize, _pool.isDirect()); checkAggregateLimit(space); _buffers.add(_aggregate); } diff --git a/jetty-core/jetty-io/src/test/java/org/eclipse/jetty/io/BufferedContentSinkTest.java b/jetty-core/jetty-io/src/test/java/org/eclipse/jetty/io/BufferedContentSinkTest.java index 6f86ab91b16..52382499211 100644 --- a/jetty-core/jetty-io/src/test/java/org/eclipse/jetty/io/BufferedContentSinkTest.java +++ b/jetty-core/jetty-io/src/test/java/org/eclipse/jetty/io/BufferedContentSinkTest.java @@ -32,6 +32,7 @@ import org.eclipse.jetty.io.content.AsyncContent; import org.eclipse.jetty.io.content.BufferedContentSink; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; +import org.eclipse.jetty.util.IO; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -257,7 +258,7 @@ public class BufferedContentSinkTest 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(); buffered.write(false, BufferUtil.toBuffer("Hello "), callback); @@ -485,7 +486,7 @@ public class BufferedContentSinkTest try (AsyncContent async = new AsyncContent()) { 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); Callback callback = new Callback() { @@ -571,7 +572,7 @@ public class BufferedContentSinkTest try (AsyncContent async = new AsyncContent()) { 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); Callback callback = new Callback() { diff --git a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnectionFactory.java b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnectionFactory.java index 130324f1ef8..db5087b7927 100644 --- a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnectionFactory.java +++ b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnectionFactory.java @@ -19,6 +19,7 @@ import java.util.List; import org.eclipse.jetty.io.AbstractConnection; import org.eclipse.jetty.io.EndPoint; 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.ManagedObject; import org.eclipse.jetty.util.component.ContainerLifeCycle; @@ -32,7 +33,7 @@ public abstract class AbstractConnectionFactory extends ContainerLifeCycle imple { private final String _protocol; private final List _protocols; - private int _inputBufferSize = 8192; + private int _inputBufferSize = IO.DEFAULT_BUFFER_SIZE; protected AbstractConnectionFactory(String protocol) { diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java index e70c49fc780..8e672a6ce43 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java @@ -664,11 +664,11 @@ public class BufferUtil 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()) { - int l = is.read(tmp.array(), 0, 8192); + int l = is.read(tmp.array(), 0, IO.DEFAULT_BUFFER_SIZE); if (l < 0) break; tmp.position(0); @@ -688,7 +688,7 @@ public class BufferUtil else { int totalRead = 0; - ByteBuffer tmp = allocate(8192); + ByteBuffer tmp = allocate(IO.DEFAULT_BUFFER_SIZE); while (BufferUtil.space(tmp) > 0 && BufferUtil.space(buffer) > 0) { int read = is.read(tmp.array(), 0, Math.min(BufferUtil.space(tmp), BufferUtil.space(buffer))); diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/IO.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/IO.java index 9948480185a..5b78681da0c 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/IO.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/IO.java @@ -57,6 +57,8 @@ public class IO { private static final Logger LOG = LoggerFactory.getLogger(IO.class); + public static final int DEFAULT_BUFFER_SIZE = 8192; + public static final String CRLF = "\r\n"; diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java index 0164a4673bd..b83bd4780cc 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/UrlEncoded.java @@ -606,7 +606,7 @@ public class UrlEncoded public static void decodeUtf16To(InputStream in, BiConsumer adder, int maxLength, int maxKeys) throws IOException { 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); decodeTo(buf.getBuffer().toString(), adder, StandardCharsets.UTF_16, maxKeys);