First round of cleanup codec-http2
This commit is contained in:
parent
b92b65e557
commit
22c13271d1
@ -35,11 +35,11 @@ public enum Http2Error {
|
||||
|
||||
private final int code;
|
||||
|
||||
private Http2Error(int code) {
|
||||
Http2Error(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return this.code;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
@ -56,8 +56,8 @@ public class DefaultHttp2Connection implements Http2Connection {
|
||||
private ChannelFutureListener closeListener;
|
||||
|
||||
public DefaultHttp2Connection(boolean server) {
|
||||
this.localEndpoint = new DefaultEndpoint(server);
|
||||
this.remoteEndpoint = new DefaultEndpoint(!server);
|
||||
localEndpoint = new DefaultEndpoint(server);
|
||||
remoteEndpoint = new DefaultEndpoint(!server);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -158,18 +158,6 @@ public class DefaultHttp2Connection implements Http2Connection {
|
||||
return closeListener;
|
||||
}
|
||||
|
||||
private void notifyStreamClosed(int id) {
|
||||
for (Listener listener : listeners) {
|
||||
listener.streamClosed(id);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyStreamCreated(int id) {
|
||||
for (Listener listener : listeners) {
|
||||
listener.streamCreated(id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple stream implementation. Streams can be compared to each other by priority.
|
||||
*/
|
||||
@ -180,7 +168,7 @@ public class DefaultHttp2Connection implements Http2Connection {
|
||||
|
||||
public DefaultStream(int id) {
|
||||
this.id = id;
|
||||
this.priority = DEFAULT_STREAM_PRIORITY;
|
||||
priority = DEFAULT_STREAM_PRIORITY;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -331,6 +319,12 @@ public class DefaultHttp2Connection implements Http2Connection {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyStreamClosed(int id) {
|
||||
for (Listener listener : listeners) {
|
||||
listener.streamClosed(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -406,7 +400,7 @@ public class DefaultHttp2Connection implements Http2Connection {
|
||||
|
||||
@Override
|
||||
public void setPushToAllowed(boolean allow) {
|
||||
this.pushToAllowed = allow;
|
||||
pushToAllowed = allow;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -453,5 +447,11 @@ public class DefaultHttp2Connection implements Http2Connection {
|
||||
private boolean isLocal() {
|
||||
return this == localEndpoint;
|
||||
}
|
||||
|
||||
private void notifyStreamCreated(int id) {
|
||||
for (Listener listener : listeners) {
|
||||
listener.streamCreated(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ import com.google.common.collect.Maps;
|
||||
public class DefaultInboundFlowController implements InboundFlowController {
|
||||
|
||||
private int initialWindowSize = DEFAULT_FLOW_CONTROL_WINDOW_SIZE;
|
||||
private StreamWindow connectionWindow = new StreamWindow(CONNECTION_STREAM_ID);
|
||||
private final StreamWindow connectionWindow = new StreamWindow(CONNECTION_STREAM_ID);
|
||||
private final Map<Integer, StreamWindow> streamWindows = Maps.newHashMap();
|
||||
|
||||
public DefaultInboundFlowController(Http2Connection connection) {
|
||||
@ -134,7 +134,7 @@ public class DefaultInboundFlowController implements InboundFlowController {
|
||||
|
||||
public StreamWindow(int streamId) {
|
||||
this.streamId = streamId;
|
||||
this.windowSize = initialWindowSize;
|
||||
windowSize = initialWindowSize;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
|
@ -79,7 +79,7 @@ public class DefaultOutboundFlowController implements OutboundFlowController {
|
||||
|
||||
@Override
|
||||
public void updateOutboundWindowSize(int streamId, int delta) throws Http2Exception {
|
||||
StreamState streamWindow = null;
|
||||
StreamState streamWindow;
|
||||
if (streamId == CONNECTION_STREAM_ID) {
|
||||
// Update the connection window and write any pending frames for all streams.
|
||||
addAndGetConnectionWindowSize(delta);
|
||||
@ -146,7 +146,7 @@ public class DefaultOutboundFlowController implements OutboundFlowController {
|
||||
* bytes. The reader index on the input frame is then advanced by the number of bytes. The
|
||||
* returned frame will not have end-of-stream set.
|
||||
*/
|
||||
private Http2DataFrame readPartialFrame(Http2DataFrame frame, int numBytes) {
|
||||
private static Http2DataFrame readPartialFrame(Http2DataFrame frame, int numBytes) {
|
||||
return new DefaultHttp2DataFrame.Builder().setStreamId(frame.getStreamId())
|
||||
.setContent(frame.content().readSlice(numBytes).retain()).build();
|
||||
}
|
||||
@ -154,7 +154,7 @@ public class DefaultOutboundFlowController implements OutboundFlowController {
|
||||
/**
|
||||
* Indicates whether applying the delta to the given value will cause an integer overflow.
|
||||
*/
|
||||
private boolean isIntegerOverflow(int previousValue, int delta) {
|
||||
private static boolean isIntegerOverflow(int previousValue, int delta) {
|
||||
return delta > 0 && (Integer.MAX_VALUE - delta) < previousValue;
|
||||
}
|
||||
|
||||
@ -263,7 +263,7 @@ public class DefaultOutboundFlowController implements OutboundFlowController {
|
||||
/**
|
||||
* Pending write for a single data frame.
|
||||
*/
|
||||
private class PendingWrite {
|
||||
private static class PendingWrite {
|
||||
private final Http2DataFrame frame;
|
||||
private final FrameWriter writer;
|
||||
|
||||
|
@ -157,7 +157,6 @@ public class Http2ConnectionHandler extends ChannelHandlerAdapter {
|
||||
handleOutboundSettings(ctx, (Http2SettingsFrame) msg, promise);
|
||||
} else {
|
||||
ctx.write(msg, promise);
|
||||
return;
|
||||
}
|
||||
|
||||
} catch (Throwable e) {
|
||||
@ -328,7 +327,7 @@ public class Http2ConnectionHandler extends ChannelHandlerAdapter {
|
||||
ctx.fireChannelRead(frame);
|
||||
}
|
||||
|
||||
private void handleInboundPing(ChannelHandlerContext ctx, Http2PingFrame frame) {
|
||||
private static void handleInboundPing(ChannelHandlerContext ctx, Http2PingFrame frame) {
|
||||
if (frame.isAck()) {
|
||||
// The remote enpoint is responding to an Ack that we sent.
|
||||
ctx.fireChannelRead(frame);
|
||||
@ -510,13 +509,13 @@ public class Http2ConnectionHandler extends ChannelHandlerAdapter {
|
||||
ctx.writeAndFlush(frame, promise);
|
||||
}
|
||||
|
||||
private void handleOutboundGoAway() throws Http2Exception {
|
||||
private static void handleOutboundGoAway() throws Http2Exception {
|
||||
// Why is this being sent? Intercept it and fail the write.
|
||||
// Should have sent a CLOSE ChannelStateEvent
|
||||
throw format(PROTOCOL_ERROR, "Another handler attempted to send GoAway.");
|
||||
}
|
||||
|
||||
private void handleOutboundWindowUpdate() throws Http2Exception {
|
||||
private static void handleOutboundWindowUpdate() throws Http2Exception {
|
||||
// Why is this being sent? Intercept it and fail the write.
|
||||
throw format(PROTOCOL_ERROR, "Another handler attempted to send window update.");
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public interface Http2Stream extends Comparable<Http2Stream> {
|
||||
* The allowed states of an HTTP2 stream.
|
||||
*/
|
||||
enum State {
|
||||
IDLE, RESERVED_LOCAL, RESERVED_REMOTE, OPEN, HALF_CLOSED_LOCAL, HALF_CLOSED_REMOTE, CLOSED;
|
||||
IDLE, RESERVED_LOCAL, RESERVED_REMOTE, OPEN, HALF_CLOSED_LOCAL, HALF_CLOSED_REMOTE, CLOSED
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,9 +33,9 @@ public final class DefaultHttp2DataFrame extends DefaultByteBufHolder implements
|
||||
|
||||
private DefaultHttp2DataFrame(Builder builder) {
|
||||
super(builder.content);
|
||||
this.streamId = builder.streamId;
|
||||
this.endOfStream = builder.endOfStream;
|
||||
this.paddingLength = builder.paddingLength;
|
||||
streamId = builder.streamId;
|
||||
endOfStream = builder.endOfStream;
|
||||
paddingLength = builder.paddingLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -180,7 +180,7 @@ public final class DefaultHttp2DataFrame extends DefaultByteBufHolder implements
|
||||
return new DefaultHttp2DataFrame(this);
|
||||
}
|
||||
|
||||
private void verifyLength(int paddingLength, ByteBuf data) {
|
||||
private static void verifyLength(int paddingLength, ByteBuf data) {
|
||||
int maxLength = MAX_FRAME_PAYLOAD_LENGTH;
|
||||
maxLength -= paddingLength;
|
||||
if (data.readableBytes() > maxLength) {
|
||||
|
@ -32,8 +32,8 @@ public final class DefaultHttp2GoAwayFrame extends DefaultByteBufHolder implemen
|
||||
|
||||
private DefaultHttp2GoAwayFrame(Builder builder) {
|
||||
super(builder.debugData);
|
||||
this.lastStreamId = builder.lastStreamId;
|
||||
this.errorCode = builder.errorCode;
|
||||
lastStreamId = builder.lastStreamId;
|
||||
errorCode = builder.errorCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,10 +27,10 @@ public final class DefaultHttp2HeadersFrame implements Http2HeadersFrame {
|
||||
private final Http2Headers headers;
|
||||
|
||||
private DefaultHttp2HeadersFrame(Builder builder) {
|
||||
this.streamId = builder.streamId;
|
||||
this.priority = builder.priority;
|
||||
this.headers = builder.headersBuilder.build();
|
||||
this.endOfStream = builder.endOfStream;
|
||||
streamId = builder.streamId;
|
||||
priority = builder.priority;
|
||||
headers = builder.headersBuilder.build();
|
||||
endOfStream = builder.endOfStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -98,13 +98,13 @@ public final class DefaultHttp2HeadersFrame implements Http2HeadersFrame {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DefaultHttp2HeadersFrame [streamId=" + streamId + ", priority=" + priority
|
||||
+ ", endOfStream=" + endOfStream + ", headers=" + headers + "]";
|
||||
+ ", endOfStream=" + endOfStream + ", headers=" + headers + ']';
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private int streamId;
|
||||
private int priority = DEFAULT_STREAM_PRIORITY;
|
||||
private Http2Headers.Builder headersBuilder = new Http2Headers.Builder();
|
||||
private final Http2Headers.Builder headersBuilder = new Http2Headers.Builder();
|
||||
private boolean endOfStream;
|
||||
|
||||
public Builder setStreamId(int streamId) {
|
||||
@ -133,7 +133,7 @@ public final class DefaultHttp2HeadersFrame implements Http2HeadersFrame {
|
||||
}
|
||||
|
||||
public Builder setHeaders(Http2Headers headers) {
|
||||
this.headersBuilder.addHeaders(headers);
|
||||
headersBuilder.addHeaders(headers);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ public final class DefaultHttp2PingFrame extends DefaultByteBufHolder implements
|
||||
|
||||
private DefaultHttp2PingFrame(Builder builder) {
|
||||
super(builder.data);
|
||||
this.ack = builder.ack;
|
||||
ack = builder.ack;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,8 +24,8 @@ public final class DefaultHttp2PriorityFrame implements Http2PriorityFrame {
|
||||
private final int priority;
|
||||
|
||||
private DefaultHttp2PriorityFrame(Builder builder) {
|
||||
this.streamId = builder.streamId;
|
||||
this.priority = builder.priority;
|
||||
streamId = builder.streamId;
|
||||
priority = builder.priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,9 +24,9 @@ public final class DefaultHttp2PushPromiseFrame implements Http2PushPromiseFrame
|
||||
private final Http2Headers headers;
|
||||
|
||||
private DefaultHttp2PushPromiseFrame(Builder builder) {
|
||||
this.streamId = builder.streamId;
|
||||
this.promisedStreamId = builder.promisedStreamId;
|
||||
this.headers = builder.headers;
|
||||
streamId = builder.streamId;
|
||||
promisedStreamId = builder.promisedStreamId;
|
||||
headers = builder.headers;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -90,7 +90,7 @@ public final class DefaultHttp2PushPromiseFrame implements Http2PushPromiseFrame
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DefaultHttp2PushPromiseFrame [streamId=" + streamId + ", promisedStreamId="
|
||||
+ promisedStreamId + ", headers=" + headers + "]";
|
||||
+ promisedStreamId + ", headers=" + headers + ']';
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
@ -25,8 +25,8 @@ public final class DefaultHttp2RstStreamFrame implements Http2RstStreamFrame {
|
||||
private final long errorCode;
|
||||
|
||||
private DefaultHttp2RstStreamFrame(Builder builder) {
|
||||
this.streamId = builder.streamId;
|
||||
this.errorCode = builder.errorCode;
|
||||
streamId = builder.streamId;
|
||||
errorCode = builder.errorCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,11 +27,11 @@ public final class DefaultHttp2SettingsFrame implements Http2SettingsFrame {
|
||||
private final Integer initialWindowSize;
|
||||
|
||||
private DefaultHttp2SettingsFrame(Builder builder) {
|
||||
this.ack = builder.ack;
|
||||
this.headerTableSize = builder.headerTableSize;
|
||||
this.pushEnabled = builder.pushEnabled;
|
||||
this.maxConcurrentStreams = builder.maxConcurrentStreams;
|
||||
this.initialWindowSize = builder.initialWindowSize;
|
||||
ack = builder.ack;
|
||||
headerTableSize = builder.headerTableSize;
|
||||
pushEnabled = builder.pushEnabled;
|
||||
maxConcurrentStreams = builder.maxConcurrentStreams;
|
||||
initialWindowSize = builder.initialWindowSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,8 +24,8 @@ public final class DefaultHttp2WindowUpdateFrame implements Http2WindowUpdateFra
|
||||
private final int windowSizeIncrement;
|
||||
|
||||
private DefaultHttp2WindowUpdateFrame(Builder builder) {
|
||||
this.streamId = builder.streamId;
|
||||
this.windowSizeIncrement = builder.windowSizeIncrement;
|
||||
streamId = builder.streamId;
|
||||
windowSizeIncrement = builder.windowSizeIncrement;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -62,7 +62,7 @@ public final class Http2FrameCodecUtil {
|
||||
*/
|
||||
public static int readUnsignedInt(ByteBuf buf) {
|
||||
int offset = buf.readerIndex();
|
||||
int value = (buf.getByte(offset + 0) & 0x7F) << 24 | (buf.getByte(offset + 1) & 0xFF) << 16
|
||||
int value = (buf.getByte(offset) & 0x7F) << 24 | (buf.getByte(offset + 1) & 0xFF) << 16
|
||||
| (buf.getByte(offset + 2) & 0xFF) << 8 | buf.getByte(offset + 3) & 0xFF;
|
||||
buf.skipBytes(4);
|
||||
return value;
|
||||
@ -98,10 +98,10 @@ public final class Http2FrameCodecUtil {
|
||||
*/
|
||||
public static short setPaddingFlags(short flags, int paddingLength) {
|
||||
if (paddingLength > 255) {
|
||||
flags |= Http2FrameCodecUtil.FLAG_PAD_HIGH;
|
||||
flags |= FLAG_PAD_HIGH;
|
||||
}
|
||||
if (paddingLength > 0) {
|
||||
flags |= Http2FrameCodecUtil.FLAG_PAD_LOW;
|
||||
flags |= FLAG_PAD_LOW;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
@ -26,10 +26,10 @@ public final class Http2FrameHeader {
|
||||
private final int streamId;
|
||||
|
||||
private Http2FrameHeader(Builder builder) {
|
||||
this.payloadLength = builder.payloadLength;
|
||||
this.type = builder.type;
|
||||
this.flags = builder.flags;
|
||||
this.streamId = builder.streamId;
|
||||
payloadLength = builder.payloadLength;
|
||||
type = builder.type;
|
||||
flags = builder.flags;
|
||||
streamId = builder.streamId;
|
||||
}
|
||||
|
||||
public int getPayloadLength() {
|
||||
|
@ -43,8 +43,6 @@ public interface Http2SettingsFrame extends Http2Frame {
|
||||
|
||||
/**
|
||||
* Gets the sender's initial flow control window in bytes, or {@code null} if not set.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
Integer getInitialWindowSize();
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public abstract class AbstractHeadersUnmarshaller extends AbstractHttp2FrameUnma
|
||||
/**
|
||||
* A builder for a headers/push_promise frame.
|
||||
*/
|
||||
protected abstract class FrameBuilder {
|
||||
protected abstract static class FrameBuilder {
|
||||
protected ByteBuf headerBlock;
|
||||
|
||||
abstract int getStreamId();
|
||||
|
@ -34,7 +34,7 @@ public class DefaultHttp2HeadersDecoder implements Http2HeadersDecoder {
|
||||
private final Decoder decoder;
|
||||
|
||||
public DefaultHttp2HeadersDecoder() {
|
||||
this.decoder = new Decoder(DEFAULT_MAX_HEADER_SIZE, DEFAULT_HEADER_TABLE_SIZE);
|
||||
decoder = new Decoder(DEFAULT_MAX_HEADER_SIZE, DEFAULT_HEADER_TABLE_SIZE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,6 +24,7 @@ import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import io.netty.handler.codec.http2.draft10.Http2Exception;
|
||||
import io.netty.handler.codec.http2.draft10.frame.DefaultHttp2DataFrame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2DataFrame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2Flags;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2Frame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2FrameHeader;
|
||||
|
@ -45,8 +45,8 @@ public class Http2FrameDecoder extends ByteToMessageDecoder {
|
||||
ERROR
|
||||
}
|
||||
|
||||
private final Http2FrameUnmarshaller frameUnmarshaller;
|
||||
private State state;
|
||||
private Http2FrameUnmarshaller frameUnmarshaller;
|
||||
private int payloadLength;
|
||||
|
||||
public Http2FrameDecoder() {
|
||||
@ -55,7 +55,7 @@ public class Http2FrameDecoder extends ByteToMessageDecoder {
|
||||
|
||||
public Http2FrameDecoder(Http2FrameUnmarshaller frameUnmarshaller) {
|
||||
this.frameUnmarshaller = frameUnmarshaller;
|
||||
this.state = State.FRAME_HEADER;
|
||||
state = State.FRAME_HEADER;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -26,6 +26,7 @@ import io.netty.handler.codec.http2.draft10.Http2Exception;
|
||||
import io.netty.handler.codec.http2.draft10.frame.DefaultHttp2GoAwayFrame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2Frame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2FrameHeader;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2GoAwayFrame;
|
||||
|
||||
/**
|
||||
* An unmarshaller for {@link Http2GoAwayFrame} instances. The buffer contained in the frames is a
|
||||
|
@ -29,6 +29,7 @@ import io.netty.handler.codec.http2.draft10.frame.DefaultHttp2HeadersFrame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2Flags;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2Frame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2FrameHeader;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2HeadersFrame;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
|
@ -25,6 +25,7 @@ import io.netty.handler.codec.http2.draft10.Http2Exception;
|
||||
import io.netty.handler.codec.http2.draft10.frame.DefaultHttp2PingFrame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2Frame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2FrameHeader;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2PingFrame;
|
||||
|
||||
/**
|
||||
* An unmarshaller for {@link Http2PingFrame} instances. The buffer contained in the frames is a
|
||||
|
@ -26,6 +26,7 @@ import io.netty.handler.codec.http2.draft10.Http2Exception;
|
||||
import io.netty.handler.codec.http2.draft10.frame.DefaultHttp2PriorityFrame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2Frame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2FrameHeader;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2PriorityFrame;
|
||||
|
||||
/**
|
||||
* An unmarshaller for {@link Http2PriorityFrame} instances.
|
||||
|
@ -28,6 +28,7 @@ import io.netty.handler.codec.http2.draft10.frame.DefaultHttp2PushPromiseFrame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2Flags;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2Frame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2FrameHeader;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2PushPromiseFrame;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
|
@ -25,6 +25,7 @@ import io.netty.handler.codec.http2.draft10.Http2Exception;
|
||||
import io.netty.handler.codec.http2.draft10.frame.DefaultHttp2RstStreamFrame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2Frame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2FrameHeader;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2RstStreamFrame;
|
||||
|
||||
/**
|
||||
* An unmarshaller for {@link Http2RstStreamFrame} instances.
|
||||
|
@ -29,6 +29,7 @@ import io.netty.handler.codec.http2.draft10.Http2Exception;
|
||||
import io.netty.handler.codec.http2.draft10.frame.DefaultHttp2SettingsFrame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2Frame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2FrameHeader;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2SettingsFrame;
|
||||
|
||||
/**
|
||||
* An unmarshaller for {@link Http2SettingsFrame} instances.
|
||||
|
@ -30,8 +30,17 @@ import static io.netty.handler.codec.http2.draft10.frame.Http2FrameCodecUtil.FRA
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import io.netty.handler.codec.http2.draft10.Http2Exception;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2DataFrame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2Frame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2FrameHeader;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2GoAwayFrame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2HeadersFrame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2PingFrame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2PriorityFrame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2PushPromiseFrame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2RstStreamFrame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2SettingsFrame;
|
||||
import io.netty.handler.codec.http2.draft10.frame.Http2WindowUpdateFrame;
|
||||
|
||||
/**
|
||||
* A composite {@link Http2FrameUnmarshaller} that supports all frames identified by the HTTP2 spec.
|
||||
@ -68,16 +77,16 @@ public class Http2StandardFrameUnmarshaller implements Http2FrameUnmarshaller {
|
||||
unmarshallers[FRAME_TYPE_GO_AWAY] = new Http2GoAwayFrameUnmarshaller();
|
||||
unmarshallers[FRAME_TYPE_WINDOW_UPDATE] = new Http2WindowUpdateFrameUnmarshaller();
|
||||
unmarshallers[FRAME_TYPE_CONTINUATION] = new Http2FrameUnmarshaller() {
|
||||
private String msg = "Received continuation without headers or push_promise";
|
||||
private static final String MSG = "Received continuation without headers or push_promise";
|
||||
|
||||
@Override
|
||||
public Http2FrameUnmarshaller unmarshall(Http2FrameHeader header) throws Http2Exception {
|
||||
throw protocolError(msg);
|
||||
throw protocolError(MSG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Http2Frame from(ByteBuf payload, ByteBufAllocator alloc) throws Http2Exception {
|
||||
throw protocolError(msg);
|
||||
throw protocolError(MSG);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class DefaultHttp2HeadersEncoder implements Http2HeadersEncoder {
|
||||
private final Encoder encoder;
|
||||
|
||||
public DefaultHttp2HeadersEncoder() {
|
||||
this.encoder = new Encoder(DEFAULT_HEADER_TABLE_SIZE);
|
||||
encoder = new Encoder(DEFAULT_HEADER_TABLE_SIZE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,7 +56,7 @@ public class Http2DataFrameMarshaller extends AbstractHttp2FrameMarshaller<Http2
|
||||
out.writeZero(frame.getPaddingLength());
|
||||
}
|
||||
|
||||
private Http2Flags getFlags(Http2DataFrame frame) {
|
||||
private static Http2Flags getFlags(Http2DataFrame frame) {
|
||||
short flags = 0;
|
||||
if (frame.isEndOfStream()) {
|
||||
flags |= FLAG_END_STREAM;
|
||||
|
@ -100,7 +100,7 @@ public class Http2HeadersFrameMarshaller extends AbstractHttp2FrameMarshaller<Ht
|
||||
/**
|
||||
* Writes a single continuation frame with a fragment of the header block to the output buffer.
|
||||
*/
|
||||
private void writeContinuationFrame(int streamId, ByteBuf headerBlock, ByteBuf out) {
|
||||
private static void writeContinuationFrame(int streamId, ByteBuf headerBlock, ByteBuf out) {
|
||||
ByteBuf fragment =
|
||||
headerBlock.readSlice(Math.min(headerBlock.readableBytes(), MAX_FRAME_PAYLOAD_LENGTH));
|
||||
|
||||
|
@ -77,7 +77,7 @@ public class Http2PushPromiseFrameMarshaller extends
|
||||
/**
|
||||
* Writes a single continuation frame with a fragment of the header block to the output buffer.
|
||||
*/
|
||||
private void writeContinuationFrame(int streamId, ByteBuf headerBlock, ByteBuf out) {
|
||||
private static void writeContinuationFrame(int streamId, ByteBuf headerBlock, ByteBuf out) {
|
||||
ByteBuf fragment =
|
||||
headerBlock.readSlice(Math.min(headerBlock.readableBytes(), MAX_FRAME_PAYLOAD_LENGTH));
|
||||
|
||||
|
@ -133,7 +133,7 @@ public class DefaultInboundFlowControllerTest {
|
||||
verify(frameWriter).writeFrame(eq(windowUpdate(STREAM_ID, delta)));
|
||||
}
|
||||
|
||||
private int getWindowDelta(int initialSize, int windowSize, int dataSize) {
|
||||
private static int getWindowDelta(int initialSize, int windowSize, int dataSize) {
|
||||
int newWindowSize = windowSize - dataSize;
|
||||
return initialSize - newWindowSize;
|
||||
}
|
||||
@ -151,7 +151,7 @@ public class DefaultInboundFlowControllerTest {
|
||||
verify(frameWriter, never()).writeFrame(any(Http2WindowUpdateFrame.class));
|
||||
}
|
||||
|
||||
private Http2WindowUpdateFrame windowUpdate(int streamId, int delta) {
|
||||
private static Http2WindowUpdateFrame windowUpdate(int streamId, int delta) {
|
||||
return new DefaultHttp2WindowUpdateFrame.Builder().setStreamId(streamId)
|
||||
.setWindowSizeIncrement(delta).build();
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ public class DefaultOutboundFlowControllerTest {
|
||||
frame.release(2);
|
||||
}
|
||||
|
||||
private Http2DataFrame frame(int payloadLength) {
|
||||
private static Http2DataFrame frame(int payloadLength) {
|
||||
ByteBuf buffer = Unpooled.buffer(payloadLength);
|
||||
buffer.writerIndex(payloadLength);
|
||||
return new DefaultHttp2DataFrame.Builder().setStreamId(STREAM_ID).setContent(buffer).build();
|
||||
|
@ -256,7 +256,7 @@ public class Http2FrameRoundtripTest {
|
||||
captureHandler.release();
|
||||
}
|
||||
|
||||
private void assertAndReleaseFrames(Http2Frame in, Http2Frame out) {
|
||||
private static void assertAndReleaseFrames(Http2Frame in, Http2Frame out) {
|
||||
assertEquals(in, out);
|
||||
if (in instanceof ByteBufHolder) {
|
||||
assertEquals(1, ((ByteBufHolder) in).refCnt());
|
||||
@ -298,7 +298,7 @@ public class Http2FrameRoundtripTest {
|
||||
holder.release();
|
||||
}
|
||||
|
||||
this.frame = (Http2Frame) msg;
|
||||
frame = (Http2Frame) msg;
|
||||
count++;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user