8257001: Improve Http Client Support

Reviewed-by: chegar, dfuchs, rhalade
This commit is contained in:
Rahul Yadav 2021-01-21 14:52:08 +00:00 committed by Henry Jen
parent 9bf055d359
commit 8d0faaf91a

View File

@ -121,6 +121,7 @@ class Http2Connection {
static private final int MAX_CLIENT_STREAM_ID = Integer.MAX_VALUE; // 2147483647 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 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. * Flag set when no more streams to be opened on this connection.
@ -1111,8 +1112,10 @@ class Http2Connection {
* and CONTINUATION frames from the list and return the List<Http2Frame>. * and CONTINUATION frames from the list and return the List<Http2Frame>.
*/ */
private List<HeaderFrame> encodeHeaders(OutgoingHeaders<Stream<?>> frame) { 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( List<ByteBuffer> buffers = encodeHeadersImpl(
getMaxSendFrameSize(), bufferSize,
frame.getAttachment().getRequestPseudoHeaders(), frame.getAttachment().getRequestPseudoHeaders(),
frame.getUserHeaders(), frame.getUserHeaders(),
frame.getSystemHeaders()); frame.getSystemHeaders());
@ -1135,9 +1138,9 @@ class Http2Connection {
// by the sendLock. / (see sendFrame()) // by the sendLock. / (see sendFrame())
// private final ByteBufferPool headerEncodingPool = new ByteBufferPool(); // private final ByteBufferPool headerEncodingPool = new ByteBufferPool();
private ByteBuffer getHeaderBuffer(int maxFrameSize) { private ByteBuffer getHeaderBuffer(int size) {
ByteBuffer buf = ByteBuffer.allocate(maxFrameSize); ByteBuffer buf = ByteBuffer.allocate(size);
buf.limit(maxFrameSize); buf.limit(size);
return buf; return buf;
} }
@ -1152,8 +1155,8 @@ class Http2Connection {
* header field names MUST be converted to lowercase prior to their * header field names MUST be converted to lowercase prior to their
* encoding in HTTP/2... * encoding in HTTP/2...
*/ */
private List<ByteBuffer> encodeHeadersImpl(int maxFrameSize, HttpHeaders... headers) { private List<ByteBuffer> encodeHeadersImpl(int bufferSize, HttpHeaders... headers) {
ByteBuffer buffer = getHeaderBuffer(maxFrameSize); ByteBuffer buffer = getHeaderBuffer(bufferSize);
List<ByteBuffer> buffers = new ArrayList<>(); List<ByteBuffer> buffers = new ArrayList<>();
for(HttpHeaders header : headers) { for(HttpHeaders header : headers) {
for (Map.Entry<String, List<String>> e : header.map().entrySet()) { for (Map.Entry<String, List<String>> e : header.map().entrySet()) {
@ -1164,7 +1167,7 @@ class Http2Connection {
while (!hpackOut.encode(buffer)) { while (!hpackOut.encode(buffer)) {
buffer.flip(); buffer.flip();
buffers.add(buffer); buffers.add(buffer);
buffer = getHeaderBuffer(maxFrameSize); buffer = getHeaderBuffer(bufferSize);
} }
} }
} }
@ -1174,6 +1177,7 @@ class Http2Connection {
return buffers; return buffers;
} }
private List<ByteBuffer> encodeHeaders(OutgoingHeaders<Stream<?>> oh, Stream<?> stream) { private List<ByteBuffer> encodeHeaders(OutgoingHeaders<Stream<?>> oh, Stream<?> stream) {
oh.streamid(stream.streamid); oh.streamid(stream.streamid);
if (Log.headers()) { if (Log.headers()) {