(int streamId, int payloadSize, ByteBuffer buffer)
| 513 | |
| 514 | |
| 515 | protected void readHeaderPayload(int streamId, int payloadSize, ByteBuffer buffer) |
| 516 | throws Http2Exception, IOException { |
| 517 | |
| 518 | if (log.isTraceEnabled()) { |
| 519 | log.trace(sm.getString("http2Parser.processFrameHeaders.payload", connectionId, Integer.valueOf(streamId), |
| 520 | Integer.valueOf(payloadSize))); |
| 521 | } |
| 522 | |
| 523 | int remaining = payloadSize; |
| 524 | |
| 525 | while (remaining > 0) { |
| 526 | if (headerReadBuffer.remaining() == 0) { |
| 527 | // Buffer needs expansion |
| 528 | int newSize; |
| 529 | if (headerReadBuffer.capacity() < payloadSize) { |
| 530 | // First step, expand to the current payload. That should |
| 531 | // cover most cases. |
| 532 | newSize = payloadSize; |
| 533 | } else { |
| 534 | // Header must be spread over multiple frames. Keep doubling |
| 535 | // buffer size until the header can be read. |
| 536 | newSize = headerReadBuffer.capacity() * 2; |
| 537 | } |
| 538 | headerReadBuffer = ByteBufferUtils.expand(headerReadBuffer, newSize); |
| 539 | } |
| 540 | int toRead = Math.min(headerReadBuffer.remaining(), remaining); |
| 541 | // headerReadBuffer in write mode |
| 542 | if (buffer == null) { |
| 543 | input.fill(true, headerReadBuffer, toRead); |
| 544 | } else { |
| 545 | int oldLimit = buffer.limit(); |
| 546 | buffer.limit(buffer.position() + toRead); |
| 547 | headerReadBuffer.put(buffer); |
| 548 | buffer.limit(oldLimit); |
| 549 | } |
| 550 | // switch to read mode |
| 551 | headerReadBuffer.flip(); |
| 552 | try { |
| 553 | hpackDecoder.decode(headerReadBuffer); |
| 554 | } catch (HpackException hpe) { |
| 555 | throw new ConnectionException(sm.getString("http2Parser.processFrameHeaders.decodingFailed"), |
| 556 | Http2Error.COMPRESSION_ERROR, hpe); |
| 557 | } catch (IllegalArgumentException iae) { |
| 558 | throw new StreamException("Invalid headers", Http2Error.PROTOCOL_ERROR, streamId, iae); |
| 559 | } |
| 560 | |
| 561 | // switches to write mode |
| 562 | headerReadBuffer.compact(); |
| 563 | remaining -= toRead; |
| 564 | |
| 565 | if (hpackDecoder.isHeaderCountExceeded()) { |
| 566 | StreamException headerException = new StreamException( |
| 567 | sm.getString("http2Parser.headerLimitCount", connectionId, Integer.valueOf(streamId)), |
| 568 | Http2Error.ENHANCE_YOUR_CALM, streamId); |
| 569 | hpackDecoder.getHeaderEmitter().setHeaderException(headerException); |
| 570 | } |
| 571 | |
| 572 | if (hpackDecoder.isHeaderSizeExceeded(headerReadBuffer.position())) { |
no test coverage detected