OpenJDK / jdk-updates / jdk11u
changeset 53971:15862747ee15 jdk-11.0.11+9 jdk-11.0.11-ga
8257001: Improve Http Client Support
Reviewed-by: clanger
author | mbalao |
---|---|
date | Thu, 21 Jan 2021 14:52:08 +0000 |
parents | c82c3d65c256 |
children | 62505d2b9ed4 |
files | src/java.net.http/share/classes/jdk/internal/net/http/Http2Connection.java |
diffstat | 1 files changed, 11 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/java.net.http/share/classes/jdk/internal/net/http/Http2Connection.java Tue Mar 02 17:14:31 2021 +0300 +++ b/src/java.net.http/share/classes/jdk/internal/net/http/Http2Connection.java Thu Jan 21 14:52:08 2021 +0000 @@ -121,6 +121,7 @@ static private final int MAX_CLIENT_STREAM_ID = Integer.MAX_VALUE; // 2147483647 static private final int MAX_SERVER_STREAM_ID = Integer.MAX_VALUE - 1; // 2147483646 + static private final int BUFFER = 8; // added as an upper bound /** * Flag set when no more streams to be opened on this connection. @@ -1090,8 +1091,10 @@ * and CONTINUATION frames from the list and return the List<Http2Frame>. */ private List<HeaderFrame> encodeHeaders(OutgoingHeaders<Stream<?>> frame) { + // max value of frame size is clamped by default frame size to avoid OOM + int bufferSize = Math.min(Math.max(getMaxSendFrameSize(), 1024), DEFAULT_FRAME_SIZE); List<ByteBuffer> buffers = encodeHeadersImpl( - getMaxSendFrameSize(), + bufferSize, frame.getAttachment().getRequestPseudoHeaders(), frame.getUserHeaders(), frame.getSystemHeaders()); @@ -1114,9 +1117,9 @@ // by the sendLock. / (see sendFrame()) // private final ByteBufferPool headerEncodingPool = new ByteBufferPool(); - private ByteBuffer getHeaderBuffer(int maxFrameSize) { - ByteBuffer buf = ByteBuffer.allocate(maxFrameSize); - buf.limit(maxFrameSize); + private ByteBuffer getHeaderBuffer(int size) { + ByteBuffer buf = ByteBuffer.allocate(size); + buf.limit(size); return buf; } @@ -1131,8 +1134,8 @@ * header field names MUST be converted to lowercase prior to their * encoding in HTTP/2... */ - private List<ByteBuffer> encodeHeadersImpl(int maxFrameSize, HttpHeaders... headers) { - ByteBuffer buffer = getHeaderBuffer(maxFrameSize); + private List<ByteBuffer> encodeHeadersImpl(int bufferSize, HttpHeaders... headers) { + ByteBuffer buffer = getHeaderBuffer(bufferSize); List<ByteBuffer> buffers = new ArrayList<>(); for(HttpHeaders header : headers) { for (Map.Entry<String, List<String>> e : header.map().entrySet()) { @@ -1143,7 +1146,7 @@ while (!hpackOut.encode(buffer)) { buffer.flip(); buffers.add(buffer); - buffer = getHeaderBuffer(maxFrameSize); + buffer = getHeaderBuffer(bufferSize); } } } @@ -1153,6 +1156,7 @@ return buffers; } + private List<ByteBuffer> encodeHeaders(OutgoingHeaders<Stream<?>> oh, Stream<?> stream) { oh.streamid(stream.streamid); if (Log.headers()) {