2015-01-20 01:48:11 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2014 The Netty Project
|
|
|
|
*
|
|
|
|
* The Netty Project licenses this file to you under the Apache License, version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the License. You may obtain a
|
|
|
|
* copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
|
|
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
* or implied. See the License for the specific language governing permissions and limitations under
|
|
|
|
* the License.
|
|
|
|
*/
|
|
|
|
package io.netty.handler.codec.http2;
|
|
|
|
|
2015-09-09 22:40:07 +02:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
import io.netty.buffer.ByteBufAllocator;
|
|
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
|
|
import io.netty.handler.codec.http2.Http2FrameReader.Configuration;
|
2016-04-29 07:52:04 +02:00
|
|
|
import io.netty.util.internal.PlatformDependent;
|
2016-04-12 14:22:41 +02:00
|
|
|
import io.netty.util.internal.UnstableApi;
|
2015-09-09 22:40:07 +02:00
|
|
|
|
2015-01-20 01:48:11 +01:00
|
|
|
import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_MAX_FRAME_SIZE;
|
|
|
|
import static io.netty.handler.codec.http2.Http2CodecUtil.FRAME_HEADER_LENGTH;
|
|
|
|
import static io.netty.handler.codec.http2.Http2CodecUtil.INT_FIELD_LENGTH;
|
2015-09-09 22:40:07 +02:00
|
|
|
import static io.netty.handler.codec.http2.Http2CodecUtil.PING_FRAME_PAYLOAD_LENGTH;
|
2015-01-20 01:48:11 +01:00
|
|
|
import static io.netty.handler.codec.http2.Http2CodecUtil.PRIORITY_ENTRY_LENGTH;
|
2015-06-18 02:33:09 +02:00
|
|
|
import static io.netty.handler.codec.http2.Http2CodecUtil.SETTINGS_INITIAL_WINDOW_SIZE;
|
2015-01-20 01:48:11 +01:00
|
|
|
import static io.netty.handler.codec.http2.Http2CodecUtil.SETTINGS_MAX_FRAME_SIZE;
|
|
|
|
import static io.netty.handler.codec.http2.Http2CodecUtil.SETTING_ENTRY_LENGTH;
|
2016-09-16 15:57:33 +02:00
|
|
|
import static io.netty.handler.codec.http2.Http2CodecUtil.headerListSizeExceeded;
|
2015-06-18 02:33:09 +02:00
|
|
|
import static io.netty.handler.codec.http2.Http2CodecUtil.isMaxFrameSizeValid;
|
|
|
|
import static io.netty.handler.codec.http2.Http2CodecUtil.readUnsignedInt;
|
2015-01-20 01:48:11 +01:00
|
|
|
import static io.netty.handler.codec.http2.Http2Error.FLOW_CONTROL_ERROR;
|
|
|
|
import static io.netty.handler.codec.http2.Http2Error.FRAME_SIZE_ERROR;
|
|
|
|
import static io.netty.handler.codec.http2.Http2Error.PROTOCOL_ERROR;
|
|
|
|
import static io.netty.handler.codec.http2.Http2Exception.connectionError;
|
2015-06-18 02:33:09 +02:00
|
|
|
import static io.netty.handler.codec.http2.Http2Exception.streamError;
|
2015-01-20 01:48:11 +01:00
|
|
|
import static io.netty.handler.codec.http2.Http2FrameTypes.CONTINUATION;
|
|
|
|
import static io.netty.handler.codec.http2.Http2FrameTypes.DATA;
|
|
|
|
import static io.netty.handler.codec.http2.Http2FrameTypes.GO_AWAY;
|
|
|
|
import static io.netty.handler.codec.http2.Http2FrameTypes.HEADERS;
|
|
|
|
import static io.netty.handler.codec.http2.Http2FrameTypes.PING;
|
|
|
|
import static io.netty.handler.codec.http2.Http2FrameTypes.PRIORITY;
|
|
|
|
import static io.netty.handler.codec.http2.Http2FrameTypes.PUSH_PROMISE;
|
|
|
|
import static io.netty.handler.codec.http2.Http2FrameTypes.RST_STREAM;
|
|
|
|
import static io.netty.handler.codec.http2.Http2FrameTypes.SETTINGS;
|
|
|
|
import static io.netty.handler.codec.http2.Http2FrameTypes.WINDOW_UPDATE;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A {@link Http2FrameReader} that supports all frame types defined by the HTTP/2 specification.
|
|
|
|
*/
|
2016-04-12 14:22:41 +02:00
|
|
|
@UnstableApi
|
2015-01-20 01:48:11 +01:00
|
|
|
public class DefaultHttp2FrameReader implements Http2FrameReader, Http2FrameSizePolicy, Configuration {
|
|
|
|
private final Http2HeadersDecoder headersDecoder;
|
|
|
|
|
2016-04-29 07:52:04 +02:00
|
|
|
/**
|
|
|
|
* {@code true} = reading headers, {@code false} = reading payload.
|
|
|
|
*/
|
|
|
|
private boolean readingHeaders = true;
|
|
|
|
/**
|
|
|
|
* Once set to {@code true} the value will never change. This is set to {@code true} if an unrecoverable error which
|
|
|
|
* renders the connection unusable.
|
|
|
|
*/
|
|
|
|
private boolean readError;
|
2015-01-20 01:48:11 +01:00
|
|
|
private byte frameType;
|
|
|
|
private int streamId;
|
|
|
|
private Http2Flags flags;
|
|
|
|
private int payloadLength;
|
|
|
|
private HeadersContinuation headersContinuation;
|
|
|
|
private int maxFrameSize;
|
|
|
|
|
2015-09-03 20:45:38 +02:00
|
|
|
/**
|
|
|
|
* Create a new instance.
|
|
|
|
* <p>
|
|
|
|
* Header names will be validated.
|
|
|
|
*/
|
2015-01-20 01:48:11 +01:00
|
|
|
public DefaultHttp2FrameReader() {
|
2015-09-03 20:45:38 +02:00
|
|
|
this(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new instance.
|
|
|
|
* @param validateHeaders {@code true} to validate headers. {@code false} to not validate headers.
|
2017-02-21 21:27:23 +01:00
|
|
|
* @see DefaultHttp2HeadersDecoder(boolean)
|
2015-09-03 20:45:38 +02:00
|
|
|
*/
|
|
|
|
public DefaultHttp2FrameReader(boolean validateHeaders) {
|
|
|
|
this(new DefaultHttp2HeadersDecoder(validateHeaders));
|
2015-01-20 01:48:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public DefaultHttp2FrameReader(Http2HeadersDecoder headersDecoder) {
|
|
|
|
this.headersDecoder = headersDecoder;
|
|
|
|
maxFrameSize = DEFAULT_MAX_FRAME_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-14 02:09:44 +01:00
|
|
|
public Http2HeadersDecoder.Configuration headersConfiguration() {
|
|
|
|
return headersDecoder.configuration();
|
2015-01-20 01:48:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Configuration configuration() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Http2FrameSizePolicy frameSizePolicy() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void maxFrameSize(int max) throws Http2Exception {
|
|
|
|
if (!isMaxFrameSizeValid(max)) {
|
|
|
|
throw streamError(streamId, FRAME_SIZE_ERROR,
|
|
|
|
"Invalid MAX_FRAME_SIZE specified in sent settings: %d", max);
|
|
|
|
}
|
|
|
|
maxFrameSize = max;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int maxFrameSize() {
|
|
|
|
return maxFrameSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void close() {
|
2017-01-14 11:51:30 +01:00
|
|
|
closeHeadersContinuation();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void closeHeadersContinuation() {
|
2015-01-20 01:48:11 +01:00
|
|
|
if (headersContinuation != null) {
|
|
|
|
headersContinuation.close();
|
2017-01-14 11:51:30 +01:00
|
|
|
headersContinuation = null;
|
2015-01-20 01:48:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readFrame(ChannelHandlerContext ctx, ByteBuf input, Http2FrameListener listener)
|
|
|
|
throws Http2Exception {
|
2016-04-29 07:52:04 +02:00
|
|
|
if (readError) {
|
|
|
|
input.skipBytes(input.readableBytes());
|
|
|
|
return;
|
|
|
|
}
|
2015-01-20 01:48:11 +01:00
|
|
|
try {
|
2016-04-29 07:52:04 +02:00
|
|
|
do {
|
|
|
|
if (readingHeaders) {
|
|
|
|
processHeaderState(input);
|
|
|
|
if (readingHeaders) {
|
|
|
|
// Wait until the entire header has arrived.
|
2015-01-20 01:48:11 +01:00
|
|
|
return;
|
2016-04-29 07:52:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The header is complete, fall into the next case to process the payload.
|
|
|
|
// This is to ensure the proper handling of zero-length payloads. In this
|
|
|
|
// case, we don't want to loop around because there may be no more data
|
|
|
|
// available, causing us to exit the loop. Instead, we just want to perform
|
|
|
|
// the first pass at payload processing now.
|
|
|
|
processPayloadState(ctx, input, listener);
|
|
|
|
if (!readingHeaders) {
|
|
|
|
// Wait until the entire payload has arrived.
|
|
|
|
return;
|
2015-01-20 01:48:11 +01:00
|
|
|
}
|
2016-04-29 07:52:04 +02:00
|
|
|
} while (input.isReadable());
|
2015-01-20 01:48:11 +01:00
|
|
|
} catch (Http2Exception e) {
|
2016-04-29 07:52:04 +02:00
|
|
|
readError = !Http2Exception.isStreamError(e);
|
2015-01-20 01:48:11 +01:00
|
|
|
throw e;
|
|
|
|
} catch (RuntimeException e) {
|
2016-04-29 07:52:04 +02:00
|
|
|
readError = true;
|
2015-01-20 01:48:11 +01:00
|
|
|
throw e;
|
2016-04-29 07:52:04 +02:00
|
|
|
} catch (Throwable cause) {
|
|
|
|
readError = true;
|
|
|
|
PlatformDependent.throwException(cause);
|
2015-01-20 01:48:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void processHeaderState(ByteBuf in) throws Http2Exception {
|
|
|
|
if (in.readableBytes() < FRAME_HEADER_LENGTH) {
|
|
|
|
// Wait until the entire frame header has been read.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read the header and prepare the unmarshaller to read the frame.
|
|
|
|
payloadLength = in.readUnsignedMedium();
|
|
|
|
if (payloadLength > maxFrameSize) {
|
2016-08-30 12:35:52 +02:00
|
|
|
throw connectionError(FRAME_SIZE_ERROR, "Frame length: %d exceeds maximum: %d", payloadLength,
|
|
|
|
maxFrameSize);
|
2015-01-20 01:48:11 +01:00
|
|
|
}
|
|
|
|
frameType = in.readByte();
|
|
|
|
flags = new Http2Flags(in.readUnsignedByte());
|
|
|
|
streamId = readUnsignedInt(in);
|
|
|
|
|
2016-04-29 07:52:04 +02:00
|
|
|
// We have consumed the data, next time we read we will be expecting to read the frame payload.
|
|
|
|
readingHeaders = false;
|
|
|
|
|
2015-01-20 01:48:11 +01:00
|
|
|
switch (frameType) {
|
|
|
|
case DATA:
|
|
|
|
verifyDataFrame();
|
|
|
|
break;
|
|
|
|
case HEADERS:
|
|
|
|
verifyHeadersFrame();
|
|
|
|
break;
|
|
|
|
case PRIORITY:
|
|
|
|
verifyPriorityFrame();
|
|
|
|
break;
|
|
|
|
case RST_STREAM:
|
|
|
|
verifyRstStreamFrame();
|
|
|
|
break;
|
|
|
|
case SETTINGS:
|
|
|
|
verifySettingsFrame();
|
|
|
|
break;
|
|
|
|
case PUSH_PROMISE:
|
|
|
|
verifyPushPromiseFrame();
|
|
|
|
break;
|
|
|
|
case PING:
|
|
|
|
verifyPingFrame();
|
|
|
|
break;
|
|
|
|
case GO_AWAY:
|
|
|
|
verifyGoAwayFrame();
|
|
|
|
break;
|
|
|
|
case WINDOW_UPDATE:
|
|
|
|
verifyWindowUpdateFrame();
|
|
|
|
break;
|
|
|
|
case CONTINUATION:
|
|
|
|
verifyContinuationFrame();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Unknown frame type, could be an extension.
|
2017-02-18 06:14:54 +01:00
|
|
|
verifyUnknownFrame();
|
2015-01-20 01:48:11 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void processPayloadState(ChannelHandlerContext ctx, ByteBuf in, Http2FrameListener listener)
|
|
|
|
throws Http2Exception {
|
|
|
|
if (in.readableBytes() < payloadLength) {
|
|
|
|
// Wait until the entire payload has been read.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-29 19:45:52 +01:00
|
|
|
// Only process up to payloadLength bytes.
|
|
|
|
int payloadEndIndex = in.readerIndex() + payloadLength;
|
2015-01-20 01:48:11 +01:00
|
|
|
|
2016-04-29 07:52:04 +02:00
|
|
|
// We have consumed the data, next time we read we will be expecting to read a frame header.
|
|
|
|
readingHeaders = true;
|
|
|
|
|
2015-01-20 01:48:11 +01:00
|
|
|
// Read the payload and fire the frame event to the listener.
|
|
|
|
switch (frameType) {
|
|
|
|
case DATA:
|
2018-11-29 19:45:52 +01:00
|
|
|
readDataFrame(ctx, in, payloadEndIndex, listener);
|
2015-01-20 01:48:11 +01:00
|
|
|
break;
|
|
|
|
case HEADERS:
|
2018-11-29 19:45:52 +01:00
|
|
|
readHeadersFrame(ctx, in, payloadEndIndex, listener);
|
2015-01-20 01:48:11 +01:00
|
|
|
break;
|
|
|
|
case PRIORITY:
|
2018-11-29 19:45:52 +01:00
|
|
|
readPriorityFrame(ctx, in, listener);
|
2015-01-20 01:48:11 +01:00
|
|
|
break;
|
|
|
|
case RST_STREAM:
|
2018-11-29 19:45:52 +01:00
|
|
|
readRstStreamFrame(ctx, in, listener);
|
2015-01-20 01:48:11 +01:00
|
|
|
break;
|
|
|
|
case SETTINGS:
|
2018-11-29 19:45:52 +01:00
|
|
|
readSettingsFrame(ctx, in, listener);
|
2015-01-20 01:48:11 +01:00
|
|
|
break;
|
|
|
|
case PUSH_PROMISE:
|
2018-11-29 19:45:52 +01:00
|
|
|
readPushPromiseFrame(ctx, in, payloadEndIndex, listener);
|
2015-01-20 01:48:11 +01:00
|
|
|
break;
|
|
|
|
case PING:
|
2018-11-29 19:45:52 +01:00
|
|
|
readPingFrame(ctx, in.readLong(), listener);
|
2015-01-20 01:48:11 +01:00
|
|
|
break;
|
|
|
|
case GO_AWAY:
|
2018-11-29 19:45:52 +01:00
|
|
|
readGoAwayFrame(ctx, in, payloadEndIndex, listener);
|
2015-01-20 01:48:11 +01:00
|
|
|
break;
|
|
|
|
case WINDOW_UPDATE:
|
2018-11-29 19:45:52 +01:00
|
|
|
readWindowUpdateFrame(ctx, in, listener);
|
2015-01-20 01:48:11 +01:00
|
|
|
break;
|
|
|
|
case CONTINUATION:
|
2018-11-29 19:45:52 +01:00
|
|
|
readContinuationFrame(in, payloadEndIndex, listener);
|
2015-01-20 01:48:11 +01:00
|
|
|
break;
|
|
|
|
default:
|
2018-11-29 19:45:52 +01:00
|
|
|
readUnknownFrame(ctx, in, payloadEndIndex, listener);
|
2015-01-20 01:48:11 +01:00
|
|
|
break;
|
|
|
|
}
|
2018-11-29 19:45:52 +01:00
|
|
|
in.readerIndex(payloadEndIndex);
|
2015-01-20 01:48:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void verifyDataFrame() throws Http2Exception {
|
2016-08-30 12:35:52 +02:00
|
|
|
verifyAssociatedWithAStream();
|
2015-01-20 01:48:11 +01:00
|
|
|
verifyNotProcessingHeaders();
|
|
|
|
verifyPayloadLength(payloadLength);
|
|
|
|
|
|
|
|
if (payloadLength < flags.getPaddingPresenceFieldLength()) {
|
|
|
|
throw streamError(streamId, FRAME_SIZE_ERROR,
|
|
|
|
"Frame length %d too small.", payloadLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void verifyHeadersFrame() throws Http2Exception {
|
2016-08-30 12:35:52 +02:00
|
|
|
verifyAssociatedWithAStream();
|
2015-01-20 01:48:11 +01:00
|
|
|
verifyNotProcessingHeaders();
|
|
|
|
verifyPayloadLength(payloadLength);
|
|
|
|
|
|
|
|
int requiredLength = flags.getPaddingPresenceFieldLength() + flags.getNumPriorityBytes();
|
|
|
|
if (payloadLength < requiredLength) {
|
|
|
|
throw streamError(streamId, FRAME_SIZE_ERROR,
|
|
|
|
"Frame length too small." + payloadLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void verifyPriorityFrame() throws Http2Exception {
|
2016-08-30 12:35:52 +02:00
|
|
|
verifyAssociatedWithAStream();
|
2015-01-20 01:48:11 +01:00
|
|
|
verifyNotProcessingHeaders();
|
|
|
|
|
|
|
|
if (payloadLength != PRIORITY_ENTRY_LENGTH) {
|
|
|
|
throw streamError(streamId, FRAME_SIZE_ERROR,
|
|
|
|
"Invalid frame length %d.", payloadLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void verifyRstStreamFrame() throws Http2Exception {
|
2016-08-30 12:35:52 +02:00
|
|
|
verifyAssociatedWithAStream();
|
2015-01-20 01:48:11 +01:00
|
|
|
verifyNotProcessingHeaders();
|
|
|
|
|
|
|
|
if (payloadLength != INT_FIELD_LENGTH) {
|
2016-08-30 12:35:52 +02:00
|
|
|
throw connectionError(FRAME_SIZE_ERROR, "Invalid frame length %d.", payloadLength);
|
2015-01-20 01:48:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void verifySettingsFrame() throws Http2Exception {
|
|
|
|
verifyNotProcessingHeaders();
|
|
|
|
verifyPayloadLength(payloadLength);
|
|
|
|
if (streamId != 0) {
|
|
|
|
throw connectionError(PROTOCOL_ERROR, "A stream ID must be zero.");
|
|
|
|
}
|
|
|
|
if (flags.ack() && payloadLength > 0) {
|
2016-08-30 12:35:52 +02:00
|
|
|
throw connectionError(FRAME_SIZE_ERROR, "Ack settings frame must have an empty payload.");
|
2015-01-20 01:48:11 +01:00
|
|
|
}
|
|
|
|
if (payloadLength % SETTING_ENTRY_LENGTH > 0) {
|
|
|
|
throw connectionError(FRAME_SIZE_ERROR, "Frame length %d invalid.", payloadLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void verifyPushPromiseFrame() throws Http2Exception {
|
|
|
|
verifyNotProcessingHeaders();
|
|
|
|
verifyPayloadLength(payloadLength);
|
|
|
|
|
|
|
|
// Subtract the length of the promised stream ID field, to determine the length of the
|
|
|
|
// rest of the payload (header block fragment + payload).
|
|
|
|
int minLength = flags.getPaddingPresenceFieldLength() + INT_FIELD_LENGTH;
|
|
|
|
if (payloadLength < minLength) {
|
|
|
|
throw streamError(streamId, FRAME_SIZE_ERROR,
|
|
|
|
"Frame length %d too small.", payloadLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void verifyPingFrame() throws Http2Exception {
|
|
|
|
verifyNotProcessingHeaders();
|
|
|
|
if (streamId != 0) {
|
|
|
|
throw connectionError(PROTOCOL_ERROR, "A stream ID must be zero.");
|
|
|
|
}
|
2015-09-09 22:40:07 +02:00
|
|
|
if (payloadLength != PING_FRAME_PAYLOAD_LENGTH) {
|
2015-01-20 01:48:11 +01:00
|
|
|
throw connectionError(FRAME_SIZE_ERROR,
|
|
|
|
"Frame length %d incorrect size for ping.", payloadLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void verifyGoAwayFrame() throws Http2Exception {
|
|
|
|
verifyNotProcessingHeaders();
|
|
|
|
verifyPayloadLength(payloadLength);
|
|
|
|
|
|
|
|
if (streamId != 0) {
|
|
|
|
throw connectionError(PROTOCOL_ERROR, "A stream ID must be zero.");
|
|
|
|
}
|
|
|
|
if (payloadLength < 8) {
|
|
|
|
throw connectionError(FRAME_SIZE_ERROR, "Frame length %d too small.", payloadLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void verifyWindowUpdateFrame() throws Http2Exception {
|
|
|
|
verifyNotProcessingHeaders();
|
|
|
|
verifyStreamOrConnectionId(streamId, "Stream ID");
|
|
|
|
|
|
|
|
if (payloadLength != INT_FIELD_LENGTH) {
|
2016-08-30 12:35:52 +02:00
|
|
|
throw connectionError(FRAME_SIZE_ERROR, "Invalid frame length %d.", payloadLength);
|
2015-01-20 01:48:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void verifyContinuationFrame() throws Http2Exception {
|
2016-08-30 12:35:52 +02:00
|
|
|
verifyAssociatedWithAStream();
|
2015-01-20 01:48:11 +01:00
|
|
|
verifyPayloadLength(payloadLength);
|
|
|
|
|
|
|
|
if (headersContinuation == null) {
|
|
|
|
throw connectionError(PROTOCOL_ERROR, "Received %s frame but not currently processing headers.",
|
|
|
|
frameType);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (streamId != headersContinuation.getStreamId()) {
|
|
|
|
throw connectionError(PROTOCOL_ERROR, "Continuation stream ID does not match pending headers. "
|
|
|
|
+ "Expected %d, but received %d.", headersContinuation.getStreamId(), streamId);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (payloadLength < flags.getPaddingPresenceFieldLength()) {
|
|
|
|
throw streamError(streamId, FRAME_SIZE_ERROR,
|
|
|
|
"Frame length %d too small for padding.", payloadLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-14 11:51:30 +01:00
|
|
|
private void verifyUnknownFrame() throws Http2Exception {
|
2017-02-18 06:14:54 +01:00
|
|
|
verifyNotProcessingHeaders();
|
2017-01-14 11:51:30 +01:00
|
|
|
}
|
|
|
|
|
2018-11-29 19:45:52 +01:00
|
|
|
private void readDataFrame(ChannelHandlerContext ctx, ByteBuf payload, int payloadEndIndex,
|
2015-01-20 01:48:11 +01:00
|
|
|
Http2FrameListener listener) throws Http2Exception {
|
2016-06-23 14:09:23 +02:00
|
|
|
int padding = readPadding(payload);
|
2016-08-30 12:35:52 +02:00
|
|
|
verifyPadding(padding);
|
2015-01-20 01:48:11 +01:00
|
|
|
|
|
|
|
// Determine how much data there is to read by removing the trailing
|
|
|
|
// padding.
|
2018-11-29 19:45:52 +01:00
|
|
|
int dataLength = lengthWithoutTrailingPadding(payloadEndIndex - payload.readerIndex(), padding);
|
2015-01-20 01:48:11 +01:00
|
|
|
|
|
|
|
ByteBuf data = payload.readSlice(dataLength);
|
|
|
|
listener.onDataRead(ctx, streamId, data, padding, flags.endOfStream());
|
|
|
|
}
|
|
|
|
|
2018-11-29 19:45:52 +01:00
|
|
|
private void readHeadersFrame(final ChannelHandlerContext ctx, ByteBuf payload, int payloadEndIndex,
|
2015-01-20 01:48:11 +01:00
|
|
|
Http2FrameListener listener) throws Http2Exception {
|
|
|
|
final int headersStreamId = streamId;
|
|
|
|
final Http2Flags headersFlags = flags;
|
|
|
|
final int padding = readPadding(payload);
|
2016-08-30 12:35:52 +02:00
|
|
|
verifyPadding(padding);
|
2015-01-20 01:48:11 +01:00
|
|
|
|
|
|
|
// The callback that is invoked is different depending on whether priority information
|
|
|
|
// is present in the headers frame.
|
|
|
|
if (flags.priorityPresent()) {
|
|
|
|
long word1 = payload.readUnsignedInt();
|
|
|
|
final boolean exclusive = (word1 & 0x80000000L) != 0;
|
|
|
|
final int streamDependency = (int) (word1 & 0x7FFFFFFFL);
|
2016-08-30 12:35:52 +02:00
|
|
|
if (streamDependency == streamId) {
|
|
|
|
throw streamError(streamId, PROTOCOL_ERROR, "A stream cannot depend on itself.");
|
|
|
|
}
|
2015-01-20 01:48:11 +01:00
|
|
|
final short weight = (short) (payload.readUnsignedByte() + 1);
|
2018-11-29 19:45:52 +01:00
|
|
|
final int lenToRead = lengthWithoutTrailingPadding(payloadEndIndex - payload.readerIndex(), padding);
|
2015-01-20 01:48:11 +01:00
|
|
|
|
|
|
|
// Create a handler that invokes the listener when the header block is complete.
|
|
|
|
headersContinuation = new HeadersContinuation() {
|
|
|
|
@Override
|
|
|
|
public int getStreamId() {
|
|
|
|
return headersStreamId;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-11-29 19:45:52 +01:00
|
|
|
public void processFragment(boolean endOfHeaders, ByteBuf fragment, int len,
|
2015-01-20 01:48:11 +01:00
|
|
|
Http2FrameListener listener) throws Http2Exception {
|
|
|
|
final HeadersBlockBuilder hdrBlockBuilder = headersBlockBuilder();
|
2018-11-29 19:45:52 +01:00
|
|
|
hdrBlockBuilder.addFragment(fragment, len, ctx.alloc(), endOfHeaders);
|
2015-01-20 01:48:11 +01:00
|
|
|
if (endOfHeaders) {
|
2015-06-18 02:33:09 +02:00
|
|
|
listener.onHeadersRead(ctx, headersStreamId, hdrBlockBuilder.headers(), streamDependency,
|
|
|
|
weight, exclusive, padding, headersFlags.endOfStream());
|
2015-01-20 01:48:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Process the initial fragment, invoking the listener's callback if end of headers.
|
2018-11-29 19:45:52 +01:00
|
|
|
headersContinuation.processFragment(flags.endOfHeaders(), payload, lenToRead, listener);
|
2017-01-14 11:51:30 +01:00
|
|
|
resetHeadersContinuationIfEnd(flags.endOfHeaders());
|
2015-01-20 01:48:11 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The priority fields are not present in the frame. Prepare a continuation that invokes
|
|
|
|
// the listener callback without priority information.
|
|
|
|
headersContinuation = new HeadersContinuation() {
|
|
|
|
@Override
|
|
|
|
public int getStreamId() {
|
|
|
|
return headersStreamId;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-11-29 19:45:52 +01:00
|
|
|
public void processFragment(boolean endOfHeaders, ByteBuf fragment, int len,
|
2015-01-20 01:48:11 +01:00
|
|
|
Http2FrameListener listener) throws Http2Exception {
|
|
|
|
final HeadersBlockBuilder hdrBlockBuilder = headersBlockBuilder();
|
2018-11-29 19:45:52 +01:00
|
|
|
hdrBlockBuilder.addFragment(fragment, len, ctx.alloc(), endOfHeaders);
|
2015-01-20 01:48:11 +01:00
|
|
|
if (endOfHeaders) {
|
|
|
|
listener.onHeadersRead(ctx, headersStreamId, hdrBlockBuilder.headers(), padding,
|
|
|
|
headersFlags.endOfStream());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Process the initial fragment, invoking the listener's callback if end of headers.
|
2018-11-29 19:45:52 +01:00
|
|
|
int len = lengthWithoutTrailingPadding(payloadEndIndex - payload.readerIndex(), padding);
|
|
|
|
headersContinuation.processFragment(flags.endOfHeaders(), payload, len, listener);
|
2017-01-14 11:51:30 +01:00
|
|
|
resetHeadersContinuationIfEnd(flags.endOfHeaders());
|
|
|
|
}
|
|
|
|
|
|
|
|
private void resetHeadersContinuationIfEnd(boolean endOfHeaders) {
|
|
|
|
if (endOfHeaders) {
|
|
|
|
closeHeadersContinuation();
|
|
|
|
}
|
2015-01-20 01:48:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void readPriorityFrame(ChannelHandlerContext ctx, ByteBuf payload,
|
|
|
|
Http2FrameListener listener) throws Http2Exception {
|
|
|
|
long word1 = payload.readUnsignedInt();
|
|
|
|
boolean exclusive = (word1 & 0x80000000L) != 0;
|
|
|
|
int streamDependency = (int) (word1 & 0x7FFFFFFFL);
|
2016-08-30 12:35:52 +02:00
|
|
|
if (streamDependency == streamId) {
|
|
|
|
throw streamError(streamId, PROTOCOL_ERROR, "A stream cannot depend on itself.");
|
|
|
|
}
|
2015-01-20 01:48:11 +01:00
|
|
|
short weight = (short) (payload.readUnsignedByte() + 1);
|
|
|
|
listener.onPriorityRead(ctx, streamId, streamDependency, weight, exclusive);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void readRstStreamFrame(ChannelHandlerContext ctx, ByteBuf payload,
|
|
|
|
Http2FrameListener listener) throws Http2Exception {
|
|
|
|
long errorCode = payload.readUnsignedInt();
|
|
|
|
listener.onRstStreamRead(ctx, streamId, errorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void readSettingsFrame(ChannelHandlerContext ctx, ByteBuf payload,
|
|
|
|
Http2FrameListener listener) throws Http2Exception {
|
|
|
|
if (flags.ack()) {
|
|
|
|
listener.onSettingsAckRead(ctx);
|
|
|
|
} else {
|
|
|
|
int numSettings = payloadLength / SETTING_ENTRY_LENGTH;
|
|
|
|
Http2Settings settings = new Http2Settings();
|
|
|
|
for (int index = 0; index < numSettings; ++index) {
|
2015-04-10 18:13:32 +02:00
|
|
|
char id = (char) payload.readUnsignedShort();
|
2015-01-20 01:48:11 +01:00
|
|
|
long value = payload.readUnsignedInt();
|
|
|
|
try {
|
2015-07-13 23:53:20 +02:00
|
|
|
settings.put(id, Long.valueOf(value));
|
2015-01-20 01:48:11 +01:00
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
switch(id) {
|
|
|
|
case SETTINGS_MAX_FRAME_SIZE:
|
2016-08-30 12:35:52 +02:00
|
|
|
throw connectionError(PROTOCOL_ERROR, e, e.getMessage());
|
2015-01-20 01:48:11 +01:00
|
|
|
case SETTINGS_INITIAL_WINDOW_SIZE:
|
|
|
|
throw connectionError(FLOW_CONTROL_ERROR, e, e.getMessage());
|
|
|
|
default:
|
|
|
|
throw connectionError(PROTOCOL_ERROR, e, e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
listener.onSettingsRead(ctx, settings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-29 19:45:52 +01:00
|
|
|
private void readPushPromiseFrame(final ChannelHandlerContext ctx, ByteBuf payload, int payloadEndIndex,
|
2015-01-20 01:48:11 +01:00
|
|
|
Http2FrameListener listener) throws Http2Exception {
|
|
|
|
final int pushPromiseStreamId = streamId;
|
|
|
|
final int padding = readPadding(payload);
|
2016-08-30 12:35:52 +02:00
|
|
|
verifyPadding(padding);
|
2015-01-20 01:48:11 +01:00
|
|
|
final int promisedStreamId = readUnsignedInt(payload);
|
|
|
|
|
|
|
|
// Create a handler that invokes the listener when the header block is complete.
|
|
|
|
headersContinuation = new HeadersContinuation() {
|
|
|
|
@Override
|
|
|
|
public int getStreamId() {
|
|
|
|
return pushPromiseStreamId;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-11-29 19:45:52 +01:00
|
|
|
public void processFragment(boolean endOfHeaders, ByteBuf fragment, int len,
|
2015-01-20 01:48:11 +01:00
|
|
|
Http2FrameListener listener) throws Http2Exception {
|
2018-11-29 19:45:52 +01:00
|
|
|
headersBlockBuilder().addFragment(fragment, len, ctx.alloc(), endOfHeaders);
|
2015-01-20 01:48:11 +01:00
|
|
|
if (endOfHeaders) {
|
2015-06-18 02:33:09 +02:00
|
|
|
listener.onPushPromiseRead(ctx, pushPromiseStreamId, promisedStreamId,
|
|
|
|
headersBlockBuilder().headers(), padding);
|
2015-01-20 01:48:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Process the initial fragment, invoking the listener's callback if end of headers.
|
2018-11-29 19:45:52 +01:00
|
|
|
int len = lengthWithoutTrailingPadding(payloadEndIndex - payload.readerIndex(), padding);
|
|
|
|
headersContinuation.processFragment(flags.endOfHeaders(), payload, len, listener);
|
2017-01-14 11:51:30 +01:00
|
|
|
resetHeadersContinuationIfEnd(flags.endOfHeaders());
|
2015-01-20 01:48:11 +01:00
|
|
|
}
|
|
|
|
|
2018-02-05 11:57:49 +01:00
|
|
|
private void readPingFrame(ChannelHandlerContext ctx, long data,
|
2015-01-20 01:48:11 +01:00
|
|
|
Http2FrameListener listener) throws Http2Exception {
|
|
|
|
if (flags.ack()) {
|
|
|
|
listener.onPingAckRead(ctx, data);
|
|
|
|
} else {
|
|
|
|
listener.onPingRead(ctx, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-29 19:45:52 +01:00
|
|
|
private static void readGoAwayFrame(ChannelHandlerContext ctx, ByteBuf payload, int payloadEndIndex,
|
2015-01-20 01:48:11 +01:00
|
|
|
Http2FrameListener listener) throws Http2Exception {
|
|
|
|
int lastStreamId = readUnsignedInt(payload);
|
|
|
|
long errorCode = payload.readUnsignedInt();
|
2018-11-29 19:45:52 +01:00
|
|
|
ByteBuf debugData = payload.readSlice(payloadEndIndex - payload.readerIndex());
|
2015-01-20 01:48:11 +01:00
|
|
|
listener.onGoAwayRead(ctx, lastStreamId, errorCode, debugData);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void readWindowUpdateFrame(ChannelHandlerContext ctx, ByteBuf payload,
|
|
|
|
Http2FrameListener listener) throws Http2Exception {
|
|
|
|
int windowSizeIncrement = readUnsignedInt(payload);
|
|
|
|
if (windowSizeIncrement == 0) {
|
|
|
|
throw streamError(streamId, PROTOCOL_ERROR,
|
|
|
|
"Received WINDOW_UPDATE with delta 0 for stream: %d", streamId);
|
|
|
|
}
|
|
|
|
listener.onWindowUpdateRead(ctx, streamId, windowSizeIncrement);
|
|
|
|
}
|
|
|
|
|
2018-11-29 19:45:52 +01:00
|
|
|
private void readContinuationFrame(ByteBuf payload, int payloadEndIndex, Http2FrameListener listener)
|
2015-01-20 01:48:11 +01:00
|
|
|
throws Http2Exception {
|
|
|
|
// Process the initial fragment, invoking the listener's callback if end of headers.
|
2018-11-29 19:45:52 +01:00
|
|
|
headersContinuation.processFragment(flags.endOfHeaders(), payload,
|
|
|
|
payloadEndIndex - payload.readerIndex(), listener);
|
2017-01-14 11:51:30 +01:00
|
|
|
resetHeadersContinuationIfEnd(flags.endOfHeaders());
|
2015-01-20 01:48:11 +01:00
|
|
|
}
|
|
|
|
|
2018-11-29 19:45:52 +01:00
|
|
|
private void readUnknownFrame(ChannelHandlerContext ctx, ByteBuf payload,
|
|
|
|
int payloadEndIndex, Http2FrameListener listener) throws Http2Exception {
|
|
|
|
payload = payload.readSlice(payloadEndIndex - payload.readerIndex());
|
2015-01-20 01:48:11 +01:00
|
|
|
listener.onUnknownFrame(ctx, frameType, streamId, flags, payload);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-06-23 14:09:23 +02:00
|
|
|
* If padding is present in the payload, reads the next byte as padding. The padding also includes the one byte
|
|
|
|
* width of the pad length field. Otherwise, returns zero.
|
2015-01-20 01:48:11 +01:00
|
|
|
*/
|
2016-06-23 14:09:23 +02:00
|
|
|
private int readPadding(ByteBuf payload) {
|
2015-01-20 01:48:11 +01:00
|
|
|
if (!flags.paddingPresent()) {
|
|
|
|
return 0;
|
|
|
|
}
|
2016-06-23 14:09:23 +02:00
|
|
|
return payload.readUnsignedByte() + 1;
|
|
|
|
}
|
|
|
|
|
2016-08-30 12:35:52 +02:00
|
|
|
private void verifyPadding(int padding) throws Http2Exception {
|
|
|
|
int len = lengthWithoutTrailingPadding(payloadLength, padding);
|
|
|
|
if (len < 0) {
|
|
|
|
throw connectionError(PROTOCOL_ERROR, "Frame payload too small for padding.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-23 14:09:23 +02:00
|
|
|
/**
|
|
|
|
* The padding parameter consists of the 1 byte pad length field and the trailing padding bytes. This method
|
|
|
|
* returns the number of readable bytes without the trailing padding.
|
|
|
|
*/
|
|
|
|
private static int lengthWithoutTrailingPadding(int readableBytes, int padding) {
|
|
|
|
return padding == 0
|
|
|
|
? readableBytes
|
|
|
|
: readableBytes - (padding - 1);
|
2015-01-20 01:48:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for processing of HEADERS and PUSH_PROMISE header blocks that potentially span
|
|
|
|
* multiple frames. The implementation of this interface will perform the final callback to the
|
|
|
|
* {@link Http2FrameListener} once the end of headers is reached.
|
|
|
|
*/
|
|
|
|
private abstract class HeadersContinuation {
|
|
|
|
private final HeadersBlockBuilder builder = new HeadersBlockBuilder();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the stream for which headers are currently being processed.
|
|
|
|
*/
|
|
|
|
abstract int getStreamId();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Processes the next fragment for the current header block.
|
|
|
|
*
|
|
|
|
* @param endOfHeaders whether the fragment is the last in the header block.
|
|
|
|
* @param fragment the fragment of the header block to be added.
|
|
|
|
* @param listener the listener to be notified if the header block is completed.
|
|
|
|
*/
|
2018-11-29 19:45:52 +01:00
|
|
|
abstract void processFragment(boolean endOfHeaders, ByteBuf fragment, int len,
|
2015-01-20 01:48:11 +01:00
|
|
|
Http2FrameListener listener) throws Http2Exception;
|
|
|
|
|
|
|
|
final HeadersBlockBuilder headersBlockBuilder() {
|
|
|
|
return builder;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free any allocated resources.
|
|
|
|
*/
|
|
|
|
final void close() {
|
|
|
|
builder.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Utility class to help with construction of the headers block that may potentially span
|
|
|
|
* multiple frames.
|
|
|
|
*/
|
|
|
|
protected class HeadersBlockBuilder {
|
|
|
|
private ByteBuf headerBlock;
|
|
|
|
|
2015-06-18 02:33:09 +02:00
|
|
|
/**
|
|
|
|
* The local header size maximum has been exceeded while accumulating bytes.
|
|
|
|
* @throws Http2Exception A connection error indicating too much data has been received.
|
|
|
|
*/
|
|
|
|
private void headerSizeExceeded() throws Http2Exception {
|
|
|
|
close();
|
2017-01-14 02:09:44 +01:00
|
|
|
headerListSizeExceeded(headersDecoder.configuration().maxHeaderListSizeGoAway());
|
2015-06-18 02:33:09 +02:00
|
|
|
}
|
|
|
|
|
2015-01-20 01:48:11 +01:00
|
|
|
/**
|
|
|
|
* Adds a fragment to the block.
|
|
|
|
*
|
|
|
|
* @param fragment the fragment of the headers block to be added.
|
|
|
|
* @param alloc allocator for new blocks if needed.
|
|
|
|
* @param endOfHeaders flag indicating whether the current frame is the end of the headers.
|
|
|
|
* This is used for an optimization for when the first fragment is the full
|
|
|
|
* block. In that case, the buffer is used directly without copying.
|
|
|
|
*/
|
2018-11-29 19:45:52 +01:00
|
|
|
final void addFragment(ByteBuf fragment, int len, ByteBufAllocator alloc,
|
|
|
|
boolean endOfHeaders) throws Http2Exception {
|
2015-01-20 01:48:11 +01:00
|
|
|
if (headerBlock == null) {
|
2018-11-29 19:45:52 +01:00
|
|
|
if (len > headersDecoder.configuration().maxHeaderListSizeGoAway()) {
|
2015-06-18 02:33:09 +02:00
|
|
|
headerSizeExceeded();
|
|
|
|
}
|
2015-01-20 01:48:11 +01:00
|
|
|
if (endOfHeaders) {
|
|
|
|
// Optimization - don't bother copying, just use the buffer as-is. Need
|
|
|
|
// to retain since we release when the header block is built.
|
2018-11-29 19:45:52 +01:00
|
|
|
headerBlock = fragment.readRetainedSlice(len);
|
2015-01-20 01:48:11 +01:00
|
|
|
} else {
|
2018-11-29 19:45:52 +01:00
|
|
|
headerBlock = alloc.buffer(len).writeBytes(fragment, len);
|
2015-01-20 01:48:11 +01:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2018-11-29 19:45:52 +01:00
|
|
|
if (headersDecoder.configuration().maxHeaderListSizeGoAway() - len <
|
2015-06-18 02:33:09 +02:00
|
|
|
headerBlock.readableBytes()) {
|
|
|
|
headerSizeExceeded();
|
|
|
|
}
|
2018-11-29 19:45:52 +01:00
|
|
|
if (headerBlock.isWritable(len)) {
|
2015-01-20 01:48:11 +01:00
|
|
|
// The buffer can hold the requested bytes, just write it directly.
|
2018-11-29 19:45:52 +01:00
|
|
|
headerBlock.writeBytes(fragment, len);
|
2015-01-20 01:48:11 +01:00
|
|
|
} else {
|
|
|
|
// Allocate a new buffer that is big enough to hold the entire header block so far.
|
2018-11-29 19:45:52 +01:00
|
|
|
ByteBuf buf = alloc.buffer(headerBlock.readableBytes() + len);
|
|
|
|
buf.writeBytes(headerBlock).writeBytes(fragment, len);
|
2015-01-20 01:48:11 +01:00
|
|
|
headerBlock.release();
|
|
|
|
headerBlock = buf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the headers from the completed headers block. After this is called, this builder
|
|
|
|
* should not be called again.
|
|
|
|
*/
|
|
|
|
Http2Headers headers() throws Http2Exception {
|
|
|
|
try {
|
2016-09-16 15:57:33 +02:00
|
|
|
return headersDecoder.decodeHeaders(streamId, headerBlock);
|
2015-01-20 01:48:11 +01:00
|
|
|
} finally {
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Closes this builder and frees any resources.
|
|
|
|
*/
|
|
|
|
void close() {
|
|
|
|
if (headerBlock != null) {
|
|
|
|
headerBlock.release();
|
|
|
|
headerBlock = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear the member variable pointing at this instance.
|
|
|
|
headersContinuation = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-18 06:14:54 +01:00
|
|
|
/**
|
|
|
|
* Verify that current state is not processing on header block
|
|
|
|
* @throws Http2Exception thrown if {@link #headersContinuation} is not null
|
|
|
|
*/
|
2015-01-20 01:48:11 +01:00
|
|
|
private void verifyNotProcessingHeaders() throws Http2Exception {
|
|
|
|
if (headersContinuation != null) {
|
2017-02-18 06:14:54 +01:00
|
|
|
throw connectionError(PROTOCOL_ERROR, "Received frame of type %s while processing headers on stream %d.",
|
|
|
|
frameType, headersContinuation.getStreamId());
|
2015-01-20 01:48:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void verifyPayloadLength(int payloadLength) throws Http2Exception {
|
|
|
|
if (payloadLength > maxFrameSize) {
|
|
|
|
throw connectionError(PROTOCOL_ERROR, "Total payload length %d exceeds max frame length.", payloadLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-30 12:35:52 +02:00
|
|
|
private void verifyAssociatedWithAStream() throws Http2Exception {
|
|
|
|
if (streamId == 0) {
|
|
|
|
throw connectionError(PROTOCOL_ERROR, "Frame of type %s must be associated with a stream.", frameType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 01:48:11 +01:00
|
|
|
private static void verifyStreamOrConnectionId(int streamId, String argumentName)
|
|
|
|
throws Http2Exception {
|
|
|
|
if (streamId < 0) {
|
|
|
|
throw connectionError(PROTOCOL_ERROR, "%s must be >= 0", argumentName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|