src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/Http2Connection.java
equal
deleted
inserted
replaced
114 Utils.getDebugLogger("Http2Connection"::toString, DEBUG); |
114 Utils.getDebugLogger("Http2Connection"::toString, DEBUG); |
115 private final System.Logger debugHpack = |
115 private final System.Logger debugHpack = |
116 Utils.getHpackLogger(this::dbgString, DEBUG_HPACK); |
116 Utils.getHpackLogger(this::dbgString, DEBUG_HPACK); |
117 static final ByteBuffer EMPTY_TRIGGER = ByteBuffer.allocate(0); |
117 static final ByteBuffer EMPTY_TRIGGER = ByteBuffer.allocate(0); |
118 |
118 |
|
119 private boolean singleStream; // used only for stream 1, then closed |
|
120 |
119 /* |
121 /* |
120 * ByteBuffer pooling strategy for HTTP/2 protocol: |
122 * ByteBuffer pooling strategy for HTTP/2 protocol: |
121 * |
123 * |
122 * In general there are 4 points where ByteBuffers are used: |
124 * In general there are 4 points where ByteBuffers are used: |
123 * - incoming/outgoing frames from/to ByteBuffers plus incoming/outgoing encrypted data |
125 * - incoming/outgoing frames from/to ByteBuffers plus incoming/outgoing encrypted data |
200 assert !prefaceSent; |
202 assert !prefaceSent; |
201 synchronized (this) { |
203 synchronized (this) { |
202 prefaceSent = true; |
204 prefaceSent = true; |
203 } |
205 } |
204 } |
206 } |
205 |
|
206 } |
207 } |
207 |
208 |
208 volatile boolean closed; |
209 volatile boolean closed; |
209 |
210 |
210 //------------------------------------- |
211 //------------------------------------- |
395 }; |
396 }; |
396 |
397 |
397 return aconn.getALPN().thenCompose(checkAlpnCF); |
398 return aconn.getALPN().thenCompose(checkAlpnCF); |
398 } |
399 } |
399 |
400 |
|
401 synchronized boolean singleStream() { |
|
402 return singleStream; |
|
403 } |
|
404 |
|
405 synchronized void setSingleStream(boolean use) { |
|
406 singleStream = use; |
|
407 } |
|
408 |
400 static String keyFor(HttpConnection connection) { |
409 static String keyFor(HttpConnection connection) { |
401 boolean isProxy = connection.isProxied(); |
410 boolean isProxy = connection.isProxied(); |
402 boolean isSecure = connection.isSecure(); |
411 boolean isSecure = connection.isSecure(); |
403 InetSocketAddress addr = connection.address(); |
412 InetSocketAddress addr = connection.address(); |
404 |
413 |
427 // S indicates secure "https" |
436 // S indicates secure "https" |
428 // H indicates host (direct) connection |
437 // H indicates host (direct) connection |
429 // P indicates proxy |
438 // P indicates proxy |
430 // Eg: "S:H:foo.com:80" |
439 // Eg: "S:H:foo.com:80" |
431 static String keyString(boolean secure, boolean proxy, String host, int port) { |
440 static String keyString(boolean secure, boolean proxy, String host, int port) { |
|
441 if (secure && port == -1) |
|
442 port = 443; |
|
443 else if (!secure && port == -1) |
|
444 port = 80; |
432 return (secure ? "S:" : "C:") + (proxy ? "P:" : "H:") + host + ":" + port; |
445 return (secure ? "S:" : "C:") + (proxy ? "P:" : "H:") + host + ":" + port; |
433 } |
446 } |
434 |
447 |
435 String key() { |
448 String key() { |
436 return this.key; |
449 return this.key; |
437 } |
450 } |
438 |
451 |
439 void putConnection() { |
452 boolean offerConnection() { |
440 client2.putConnection(this); |
453 return client2.offerConnection(this); |
441 } |
454 } |
442 |
455 |
443 private HttpPublisher publisher() { |
456 private HttpPublisher publisher() { |
444 return connection.publisher(); |
457 return connection.publisher(); |
445 } |
458 } |
462 final int getInitialSendWindowSize() { |
475 final int getInitialSendWindowSize() { |
463 return serverSettings.getParameter(INITIAL_WINDOW_SIZE); |
476 return serverSettings.getParameter(INITIAL_WINDOW_SIZE); |
464 } |
477 } |
465 |
478 |
466 void close() { |
479 void close() { |
|
480 Log.logTrace("Closing HTTP/2 connection: to {0}", connection.address()); |
467 GoAwayFrame f = new GoAwayFrame(0, ErrorFrame.NO_ERROR, "Requested by user".getBytes()); |
481 GoAwayFrame f = new GoAwayFrame(0, ErrorFrame.NO_ERROR, "Requested by user".getBytes()); |
468 // TODO: set last stream. For now zero ok. |
482 // TODO: set last stream. For now zero ok. |
469 sendFrame(f); |
483 sendFrame(f); |
470 } |
484 } |
471 |
485 |
678 if (s != null && !(s instanceof Stream.PushedStream)) { |
692 if (s != null && !(s instanceof Stream.PushedStream)) { |
679 // Since PushStreams have no request body, then they have no |
693 // Since PushStreams have no request body, then they have no |
680 // corresponding entry in the window controller. |
694 // corresponding entry in the window controller. |
681 windowController.removeStream(streamid); |
695 windowController.removeStream(streamid); |
682 } |
696 } |
683 } |
697 if (singleStream() && streams.isEmpty()) { |
|
698 // should be only 1 stream, but there might be more if server push |
|
699 close(); |
|
700 } |
|
701 } |
|
702 |
684 /** |
703 /** |
685 * Increments this connection's send Window by the amount in the given frame. |
704 * Increments this connection's send Window by the amount in the given frame. |
686 */ |
705 */ |
687 private void handleWindowUpdate(WindowUpdateFrame f) |
706 private void handleWindowUpdate(WindowUpdateFrame f) |
688 throws IOException |
707 throws IOException |