HTTP/2 protocol handler. Implements the UpgradeProtocol interface to allow HTTP/2 to be used as an upgrade from HTTP/1.1 or via ALPN.
| 44 | * from HTTP/1.1 or via ALPN. |
| 45 | */ |
| 46 | public class Http2Protocol implements UpgradeProtocol { |
| 47 | |
| 48 | /** |
| 49 | * Creates a new instance of the HTTP/2 protocol handler. |
| 50 | */ |
| 51 | public Http2Protocol() { |
| 52 | super(); |
| 53 | } |
| 54 | |
| 55 | |
| 56 | private static final Log log = LogFactory.getLog(Http2Protocol.class); |
| 57 | private static final StringManager sm = StringManager.getManager(Http2Protocol.class); |
| 58 | |
| 59 | static final long DEFAULT_READ_TIMEOUT = 5000; |
| 60 | static final long DEFAULT_WRITE_TIMEOUT = 5000; |
| 61 | static final long DEFAULT_KEEP_ALIVE_TIMEOUT = 20000; |
| 62 | static final long DEFAULT_STREAM_READ_TIMEOUT = 20000; |
| 63 | static final long DEFAULT_STREAM_WRITE_TIMEOUT = 20000; |
| 64 | // The HTTP/2 specification recommends a minimum default of 100 |
| 65 | static final long DEFAULT_MAX_CONCURRENT_STREAMS = 100; |
| 66 | // Maximum amount of streams which can be concurrently executed over |
| 67 | // a single connection |
| 68 | static final int DEFAULT_MAX_CONCURRENT_STREAM_EXECUTION = 20; |
| 69 | // Default factor used when adjusting overhead count for overhead frames |
| 70 | static final int DEFAULT_OVERHEAD_COUNT_FACTOR = 10; |
| 71 | // Default factor used when adjusting overhead count for reset frames |
| 72 | static final int DEFAULT_OVERHEAD_RESET_FACTOR = 50; |
| 73 | // Not currently configurable. This makes the practical limit for |
| 74 | // overheadCountFactor to be ~20. The exact limit will vary with traffic |
| 75 | // patterns. |
| 76 | static final int DEFAULT_OVERHEAD_REDUCTION_FACTOR = -20; |
| 77 | static final int DEFAULT_OVERHEAD_CONTINUATION_THRESHOLD = 1024; |
| 78 | static final int DEFAULT_OVERHEAD_DATA_THRESHOLD = 1024; |
| 79 | static final int DEFAULT_OVERHEAD_WINDOW_UPDATE_THRESHOLD = 1024; |
| 80 | |
| 81 | private static final String HTTP_UPGRADE_NAME = "h2c"; |
| 82 | private static final String ALPN_NAME = "h2"; |
| 83 | private static final byte[] ALPN_IDENTIFIER = ALPN_NAME.getBytes(StandardCharsets.UTF_8); |
| 84 | |
| 85 | // All timeouts in milliseconds |
| 86 | // These are the socket level timeouts |
| 87 | private long readTimeout = DEFAULT_READ_TIMEOUT; |
| 88 | private long writeTimeout = DEFAULT_WRITE_TIMEOUT; |
| 89 | private long keepAliveTimeout = DEFAULT_KEEP_ALIVE_TIMEOUT; |
| 90 | // These are the stream level timeouts |
| 91 | private long streamReadTimeout = DEFAULT_STREAM_READ_TIMEOUT; |
| 92 | private long streamWriteTimeout = DEFAULT_STREAM_WRITE_TIMEOUT; |
| 93 | |
| 94 | private long maxConcurrentStreams = DEFAULT_MAX_CONCURRENT_STREAMS; |
| 95 | private int maxConcurrentStreamExecution = DEFAULT_MAX_CONCURRENT_STREAM_EXECUTION; |
| 96 | // To advertise a different default to the client specify it here but DO NOT |
| 97 | // change the default defined in ConnectionSettingsBase. |
| 98 | private int initialWindowSize = ConnectionSettingsBase.DEFAULT_INITIAL_WINDOW_SIZE; |
| 99 | // Limits |
| 100 | private int maxHeaderCount = Constants.DEFAULT_MAX_HEADER_COUNT; |
| 101 | private int maxTrailerCount = Constants.DEFAULT_MAX_TRAILER_COUNT; |
| 102 | private int overheadCountFactor = DEFAULT_OVERHEAD_COUNT_FACTOR; |
| 103 | private int overheadResetFactor = DEFAULT_OVERHEAD_RESET_FACTOR; |
nothing calls this directly
no test coverage detected