Advertisement
AtomicOs

Client

Apr 21st, 2021
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 3.20 KB | None | 0 0
  1.  
  2. # HG changeset patch
  3. # User mbalao
  4. # Date 1611240728 0
  5. # Node ID 15862747ee15445292b4b9949b4f0f4badba4812
  6. # Parent  c82c3d65c25617c12cd0d27c4522d15a030d2b2d
  7. 8257001: Improve Http Client Support
  8. Reviewed-by: clanger
  9.  
  10. diff -r c82c3d65c256 -r 15862747ee15 src/java.net.http/share/classes/jdk/internal/net/http/Http2Connection.java
  11. --- a/src/java.net.http/share/classes/jdk/internal/net/http/Http2Connection.java    Tue Mar 02 17:14:31 2021 +0300
  12. +++ b/src/java.net.http/share/classes/jdk/internal/net/http/Http2Connection.java    Thu Jan 21 14:52:08 2021 +0000
  13. @@ -121,6 +121,7 @@
  14.  
  15.      static private final int MAX_CLIENT_STREAM_ID = Integer.MAX_VALUE; // 2147483647
  16.      static private final int MAX_SERVER_STREAM_ID = Integer.MAX_VALUE - 1; // 2147483646
  17. +    static private final int BUFFER = 8; // added as an upper bound
  18.  
  19.      /**
  20.       * Flag set when no more streams to be opened on this connection.
  21. @@ -1090,8 +1091,10 @@
  22.       * and CONTINUATION frames from the list and return the List<Http2Frame>.
  23.       */
  24.      private List<HeaderFrame> encodeHeaders(OutgoingHeaders<Stream<?>> frame) {
  25. +        // max value of frame size is clamped by default frame size to avoid OOM
  26. +        int bufferSize = Math.min(Math.max(getMaxSendFrameSize(), 1024), DEFAULT_FRAME_SIZE);
  27.          List<ByteBuffer> buffers = encodeHeadersImpl(
  28. -                getMaxSendFrameSize(),
  29. +                bufferSize,
  30.                  frame.getAttachment().getRequestPseudoHeaders(),
  31.                  frame.getUserHeaders(),
  32.                  frame.getSystemHeaders());
  33. @@ -1114,9 +1117,9 @@
  34.      // by the sendLock. / (see sendFrame())
  35.      // private final ByteBufferPool headerEncodingPool = new ByteBufferPool();
  36.  
  37. -    private ByteBuffer getHeaderBuffer(int maxFrameSize) {
  38. -        ByteBuffer buf = ByteBuffer.allocate(maxFrameSize);
  39. -        buf.limit(maxFrameSize);
  40. +    private ByteBuffer getHeaderBuffer(int size) {
  41. +        ByteBuffer buf = ByteBuffer.allocate(size);
  42. +        buf.limit(size);
  43.          return buf;
  44.      }
  45.  
  46. @@ -1131,8 +1134,8 @@
  47.       *     header field names MUST be converted to lowercase prior to their
  48.       *     encoding in HTTP/2...
  49.       */
  50. -    private List<ByteBuffer> encodeHeadersImpl(int maxFrameSize, HttpHeaders... headers) {
  51. -        ByteBuffer buffer = getHeaderBuffer(maxFrameSize);
  52. +    private List<ByteBuffer> encodeHeadersImpl(int bufferSize, HttpHeaders... headers) {
  53. +        ByteBuffer buffer = getHeaderBuffer(bufferSize);
  54.          List<ByteBuffer> buffers = new ArrayList<>();
  55.          for(HttpHeaders header : headers) {
  56.              for (Map.Entry<String, List<String>> e : header.map().entrySet()) {
  57. @@ -1143,7 +1146,7 @@
  58.                      while (!hpackOut.encode(buffer)) {
  59.                          buffer.flip();
  60.                          buffers.add(buffer);
  61. -                        buffer =  getHeaderBuffer(maxFrameSize);
  62. +                        buffer =  getHeaderBuffer(bufferSize);
  63.                      }
  64.                  }
  65.              }
  66. @@ -1153,6 +1156,7 @@
  67.          return buffers;
  68.      }
  69.  
  70. +
  71.      private List<ByteBuffer> encodeHeaders(OutgoingHeaders<Stream<?>> oh, Stream<?> stream) {
  72.          oh.streamid(stream.streamid);
  73.          if (Log.headers()) {
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement