First round of cleanup codec-http2

This commit is contained in:
Norman Maurer 2014-04-05 16:17:42 +02:00
parent b92b65e557
commit 22c13271d1
37 changed files with 97 additions and 83 deletions

View File

@ -35,11 +35,11 @@ public enum Http2Error {
private final int code; private final int code;
private Http2Error(int code) { Http2Error(int code) {
this.code = code; this.code = code;
} }
public int getCode() { public int getCode() {
return this.code; return code;
} }
} }

View File

@ -56,8 +56,8 @@ public class DefaultHttp2Connection implements Http2Connection {
private ChannelFutureListener closeListener; private ChannelFutureListener closeListener;
public DefaultHttp2Connection(boolean server) { public DefaultHttp2Connection(boolean server) {
this.localEndpoint = new DefaultEndpoint(server); localEndpoint = new DefaultEndpoint(server);
this.remoteEndpoint = new DefaultEndpoint(!server); remoteEndpoint = new DefaultEndpoint(!server);
} }
@Override @Override
@ -158,18 +158,6 @@ public class DefaultHttp2Connection implements Http2Connection {
return closeListener; 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. * 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) { public DefaultStream(int id) {
this.id = id; this.id = id;
this.priority = DEFAULT_STREAM_PRIORITY; priority = DEFAULT_STREAM_PRIORITY;
} }
@Override @Override
@ -331,6 +319,12 @@ public class DefaultHttp2Connection implements Http2Connection {
return false; return false;
} }
} }
private void notifyStreamClosed(int id) {
for (Listener listener : listeners) {
listener.streamClosed(id);
}
}
} }
/** /**
@ -406,7 +400,7 @@ public class DefaultHttp2Connection implements Http2Connection {
@Override @Override
public void setPushToAllowed(boolean allow) { public void setPushToAllowed(boolean allow) {
this.pushToAllowed = allow; pushToAllowed = allow;
} }
@Override @Override
@ -453,5 +447,11 @@ public class DefaultHttp2Connection implements Http2Connection {
private boolean isLocal() { private boolean isLocal() {
return this == localEndpoint; return this == localEndpoint;
} }
private void notifyStreamCreated(int id) {
for (Listener listener : listeners) {
listener.streamCreated(id);
}
}
} }
} }

View File

@ -35,7 +35,7 @@ import com.google.common.collect.Maps;
public class DefaultInboundFlowController implements InboundFlowController { public class DefaultInboundFlowController implements InboundFlowController {
private int initialWindowSize = DEFAULT_FLOW_CONTROL_WINDOW_SIZE; 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(); private final Map<Integer, StreamWindow> streamWindows = Maps.newHashMap();
public DefaultInboundFlowController(Http2Connection connection) { public DefaultInboundFlowController(Http2Connection connection) {
@ -134,7 +134,7 @@ public class DefaultInboundFlowController implements InboundFlowController {
public StreamWindow(int streamId) { public StreamWindow(int streamId) {
this.streamId = streamId; this.streamId = streamId;
this.windowSize = initialWindowSize; windowSize = initialWindowSize;
} }
public int getSize() { public int getSize() {

View File

@ -79,7 +79,7 @@ public class DefaultOutboundFlowController implements OutboundFlowController {
@Override @Override
public void updateOutboundWindowSize(int streamId, int delta) throws Http2Exception { public void updateOutboundWindowSize(int streamId, int delta) throws Http2Exception {
StreamState streamWindow = null; StreamState streamWindow;
if (streamId == CONNECTION_STREAM_ID) { if (streamId == CONNECTION_STREAM_ID) {
// Update the connection window and write any pending frames for all streams. // Update the connection window and write any pending frames for all streams.
addAndGetConnectionWindowSize(delta); 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 * 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. * 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()) return new DefaultHttp2DataFrame.Builder().setStreamId(frame.getStreamId())
.setContent(frame.content().readSlice(numBytes).retain()).build(); .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. * 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; return delta > 0 && (Integer.MAX_VALUE - delta) < previousValue;
} }
@ -263,7 +263,7 @@ public class DefaultOutboundFlowController implements OutboundFlowController {
/** /**
* Pending write for a single data frame. * Pending write for a single data frame.
*/ */
private class PendingWrite { private static class PendingWrite {
private final Http2DataFrame frame; private final Http2DataFrame frame;
private final FrameWriter writer; private final FrameWriter writer;

View File

@ -157,7 +157,6 @@ public class Http2ConnectionHandler extends ChannelHandlerAdapter {
handleOutboundSettings(ctx, (Http2SettingsFrame) msg, promise); handleOutboundSettings(ctx, (Http2SettingsFrame) msg, promise);
} else { } else {
ctx.write(msg, promise); ctx.write(msg, promise);
return;
} }
} catch (Throwable e) { } catch (Throwable e) {
@ -328,7 +327,7 @@ public class Http2ConnectionHandler extends ChannelHandlerAdapter {
ctx.fireChannelRead(frame); ctx.fireChannelRead(frame);
} }
private void handleInboundPing(ChannelHandlerContext ctx, Http2PingFrame frame) { private static void handleInboundPing(ChannelHandlerContext ctx, Http2PingFrame frame) {
if (frame.isAck()) { if (frame.isAck()) {
// The remote enpoint is responding to an Ack that we sent. // The remote enpoint is responding to an Ack that we sent.
ctx.fireChannelRead(frame); ctx.fireChannelRead(frame);
@ -510,13 +509,13 @@ public class Http2ConnectionHandler extends ChannelHandlerAdapter {
ctx.writeAndFlush(frame, promise); 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. // Why is this being sent? Intercept it and fail the write.
// Should have sent a CLOSE ChannelStateEvent // Should have sent a CLOSE ChannelStateEvent
throw format(PROTOCOL_ERROR, "Another handler attempted to send GoAway."); 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. // Why is this being sent? Intercept it and fail the write.
throw format(PROTOCOL_ERROR, "Another handler attempted to send window update."); throw format(PROTOCOL_ERROR, "Another handler attempted to send window update.");
} }

View File

@ -29,7 +29,7 @@ public interface Http2Stream extends Comparable<Http2Stream> {
* The allowed states of an HTTP2 stream. * The allowed states of an HTTP2 stream.
*/ */
enum State { 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
} }
/** /**

View File

@ -33,9 +33,9 @@ public final class DefaultHttp2DataFrame extends DefaultByteBufHolder implements
private DefaultHttp2DataFrame(Builder builder) { private DefaultHttp2DataFrame(Builder builder) {
super(builder.content); super(builder.content);
this.streamId = builder.streamId; streamId = builder.streamId;
this.endOfStream = builder.endOfStream; endOfStream = builder.endOfStream;
this.paddingLength = builder.paddingLength; paddingLength = builder.paddingLength;
} }
@Override @Override
@ -180,7 +180,7 @@ public final class DefaultHttp2DataFrame extends DefaultByteBufHolder implements
return new DefaultHttp2DataFrame(this); 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; int maxLength = MAX_FRAME_PAYLOAD_LENGTH;
maxLength -= paddingLength; maxLength -= paddingLength;
if (data.readableBytes() > maxLength) { if (data.readableBytes() > maxLength) {

View File

@ -32,8 +32,8 @@ public final class DefaultHttp2GoAwayFrame extends DefaultByteBufHolder implemen
private DefaultHttp2GoAwayFrame(Builder builder) { private DefaultHttp2GoAwayFrame(Builder builder) {
super(builder.debugData); super(builder.debugData);
this.lastStreamId = builder.lastStreamId; lastStreamId = builder.lastStreamId;
this.errorCode = builder.errorCode; errorCode = builder.errorCode;
} }
@Override @Override

View File

@ -27,10 +27,10 @@ public final class DefaultHttp2HeadersFrame implements Http2HeadersFrame {
private final Http2Headers headers; private final Http2Headers headers;
private DefaultHttp2HeadersFrame(Builder builder) { private DefaultHttp2HeadersFrame(Builder builder) {
this.streamId = builder.streamId; streamId = builder.streamId;
this.priority = builder.priority; priority = builder.priority;
this.headers = builder.headersBuilder.build(); headers = builder.headersBuilder.build();
this.endOfStream = builder.endOfStream; endOfStream = builder.endOfStream;
} }
@Override @Override
@ -98,13 +98,13 @@ public final class DefaultHttp2HeadersFrame implements Http2HeadersFrame {
@Override @Override
public String toString() { public String toString() {
return "DefaultHttp2HeadersFrame [streamId=" + streamId + ", priority=" + priority return "DefaultHttp2HeadersFrame [streamId=" + streamId + ", priority=" + priority
+ ", endOfStream=" + endOfStream + ", headers=" + headers + "]"; + ", endOfStream=" + endOfStream + ", headers=" + headers + ']';
} }
public static class Builder { public static class Builder {
private int streamId; private int streamId;
private int priority = DEFAULT_STREAM_PRIORITY; private int priority = DEFAULT_STREAM_PRIORITY;
private Http2Headers.Builder headersBuilder = new Http2Headers.Builder(); private final Http2Headers.Builder headersBuilder = new Http2Headers.Builder();
private boolean endOfStream; private boolean endOfStream;
public Builder setStreamId(int streamId) { public Builder setStreamId(int streamId) {
@ -133,7 +133,7 @@ public final class DefaultHttp2HeadersFrame implements Http2HeadersFrame {
} }
public Builder setHeaders(Http2Headers headers) { public Builder setHeaders(Http2Headers headers) {
this.headersBuilder.addHeaders(headers); headersBuilder.addHeaders(headers);
return this; return this;
} }

View File

@ -29,7 +29,7 @@ public final class DefaultHttp2PingFrame extends DefaultByteBufHolder implements
private DefaultHttp2PingFrame(Builder builder) { private DefaultHttp2PingFrame(Builder builder) {
super(builder.data); super(builder.data);
this.ack = builder.ack; ack = builder.ack;
} }
@Override @Override

View File

@ -24,8 +24,8 @@ public final class DefaultHttp2PriorityFrame implements Http2PriorityFrame {
private final int priority; private final int priority;
private DefaultHttp2PriorityFrame(Builder builder) { private DefaultHttp2PriorityFrame(Builder builder) {
this.streamId = builder.streamId; streamId = builder.streamId;
this.priority = builder.priority; priority = builder.priority;
} }
@Override @Override

View File

@ -24,9 +24,9 @@ public final class DefaultHttp2PushPromiseFrame implements Http2PushPromiseFrame
private final Http2Headers headers; private final Http2Headers headers;
private DefaultHttp2PushPromiseFrame(Builder builder) { private DefaultHttp2PushPromiseFrame(Builder builder) {
this.streamId = builder.streamId; streamId = builder.streamId;
this.promisedStreamId = builder.promisedStreamId; promisedStreamId = builder.promisedStreamId;
this.headers = builder.headers; headers = builder.headers;
} }
@Override @Override
@ -90,7 +90,7 @@ public final class DefaultHttp2PushPromiseFrame implements Http2PushPromiseFrame
@Override @Override
public String toString() { public String toString() {
return "DefaultHttp2PushPromiseFrame [streamId=" + streamId + ", promisedStreamId=" return "DefaultHttp2PushPromiseFrame [streamId=" + streamId + ", promisedStreamId="
+ promisedStreamId + ", headers=" + headers + "]"; + promisedStreamId + ", headers=" + headers + ']';
} }
public static class Builder { public static class Builder {

View File

@ -25,8 +25,8 @@ public final class DefaultHttp2RstStreamFrame implements Http2RstStreamFrame {
private final long errorCode; private final long errorCode;
private DefaultHttp2RstStreamFrame(Builder builder) { private DefaultHttp2RstStreamFrame(Builder builder) {
this.streamId = builder.streamId; streamId = builder.streamId;
this.errorCode = builder.errorCode; errorCode = builder.errorCode;
} }
@Override @Override

View File

@ -27,11 +27,11 @@ public final class DefaultHttp2SettingsFrame implements Http2SettingsFrame {
private final Integer initialWindowSize; private final Integer initialWindowSize;
private DefaultHttp2SettingsFrame(Builder builder) { private DefaultHttp2SettingsFrame(Builder builder) {
this.ack = builder.ack; ack = builder.ack;
this.headerTableSize = builder.headerTableSize; headerTableSize = builder.headerTableSize;
this.pushEnabled = builder.pushEnabled; pushEnabled = builder.pushEnabled;
this.maxConcurrentStreams = builder.maxConcurrentStreams; maxConcurrentStreams = builder.maxConcurrentStreams;
this.initialWindowSize = builder.initialWindowSize; initialWindowSize = builder.initialWindowSize;
} }
@Override @Override

View File

@ -24,8 +24,8 @@ public final class DefaultHttp2WindowUpdateFrame implements Http2WindowUpdateFra
private final int windowSizeIncrement; private final int windowSizeIncrement;
private DefaultHttp2WindowUpdateFrame(Builder builder) { private DefaultHttp2WindowUpdateFrame(Builder builder) {
this.streamId = builder.streamId; streamId = builder.streamId;
this.windowSizeIncrement = builder.windowSizeIncrement; windowSizeIncrement = builder.windowSizeIncrement;
} }
@Override @Override

View File

@ -62,7 +62,7 @@ public final class Http2FrameCodecUtil {
*/ */
public static int readUnsignedInt(ByteBuf buf) { public static int readUnsignedInt(ByteBuf buf) {
int offset = buf.readerIndex(); 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.getByte(offset + 2) & 0xFF) << 8 | buf.getByte(offset + 3) & 0xFF;
buf.skipBytes(4); buf.skipBytes(4);
return value; return value;
@ -98,10 +98,10 @@ public final class Http2FrameCodecUtil {
*/ */
public static short setPaddingFlags(short flags, int paddingLength) { public static short setPaddingFlags(short flags, int paddingLength) {
if (paddingLength > 255) { if (paddingLength > 255) {
flags |= Http2FrameCodecUtil.FLAG_PAD_HIGH; flags |= FLAG_PAD_HIGH;
} }
if (paddingLength > 0) { if (paddingLength > 0) {
flags |= Http2FrameCodecUtil.FLAG_PAD_LOW; flags |= FLAG_PAD_LOW;
} }
return flags; return flags;
} }

View File

@ -26,10 +26,10 @@ public final class Http2FrameHeader {
private final int streamId; private final int streamId;
private Http2FrameHeader(Builder builder) { private Http2FrameHeader(Builder builder) {
this.payloadLength = builder.payloadLength; payloadLength = builder.payloadLength;
this.type = builder.type; type = builder.type;
this.flags = builder.flags; flags = builder.flags;
this.streamId = builder.streamId; streamId = builder.streamId;
} }
public int getPayloadLength() { public int getPayloadLength() {

View File

@ -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. * Gets the sender's initial flow control window in bytes, or {@code null} if not set.
*
* @return
*/ */
Integer getInitialWindowSize(); Integer getInitialWindowSize();
} }

View File

@ -32,7 +32,7 @@ public abstract class AbstractHeadersUnmarshaller extends AbstractHttp2FrameUnma
/** /**
* A builder for a headers/push_promise frame. * A builder for a headers/push_promise frame.
*/ */
protected abstract class FrameBuilder { protected abstract static class FrameBuilder {
protected ByteBuf headerBlock; protected ByteBuf headerBlock;
abstract int getStreamId(); abstract int getStreamId();

View File

@ -34,7 +34,7 @@ public class DefaultHttp2HeadersDecoder implements Http2HeadersDecoder {
private final Decoder decoder; private final Decoder decoder;
public DefaultHttp2HeadersDecoder() { 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 @Override

View File

@ -24,6 +24,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
import io.netty.handler.codec.http2.draft10.Http2Exception; 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.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.Http2Flags;
import io.netty.handler.codec.http2.draft10.frame.Http2Frame; 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.Http2FrameHeader;

View File

@ -45,8 +45,8 @@ public class Http2FrameDecoder extends ByteToMessageDecoder {
ERROR ERROR
} }
private final Http2FrameUnmarshaller frameUnmarshaller;
private State state; private State state;
private Http2FrameUnmarshaller frameUnmarshaller;
private int payloadLength; private int payloadLength;
public Http2FrameDecoder() { public Http2FrameDecoder() {
@ -55,7 +55,7 @@ public class Http2FrameDecoder extends ByteToMessageDecoder {
public Http2FrameDecoder(Http2FrameUnmarshaller frameUnmarshaller) { public Http2FrameDecoder(Http2FrameUnmarshaller frameUnmarshaller) {
this.frameUnmarshaller = frameUnmarshaller; this.frameUnmarshaller = frameUnmarshaller;
this.state = State.FRAME_HEADER; state = State.FRAME_HEADER;
} }
@Override @Override

View File

@ -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.DefaultHttp2GoAwayFrame;
import io.netty.handler.codec.http2.draft10.frame.Http2Frame; 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.Http2FrameHeader;
import io.netty.handler.codec.http2.draft10.frame.Http2GoAwayFrame;
/** /**
* An unmarshaller for {@link Http2GoAwayFrame} instances. The buffer contained in the frames is a * An unmarshaller for {@link Http2GoAwayFrame} instances. The buffer contained in the frames is a

View File

@ -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.Http2Flags;
import io.netty.handler.codec.http2.draft10.frame.Http2Frame; 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.Http2FrameHeader;
import io.netty.handler.codec.http2.draft10.frame.Http2HeadersFrame;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;

View File

@ -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.DefaultHttp2PingFrame;
import io.netty.handler.codec.http2.draft10.frame.Http2Frame; 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.Http2FrameHeader;
import io.netty.handler.codec.http2.draft10.frame.Http2PingFrame;
/** /**
* An unmarshaller for {@link Http2PingFrame} instances. The buffer contained in the frames is a * An unmarshaller for {@link Http2PingFrame} instances. The buffer contained in the frames is a

View File

@ -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.DefaultHttp2PriorityFrame;
import io.netty.handler.codec.http2.draft10.frame.Http2Frame; 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.Http2FrameHeader;
import io.netty.handler.codec.http2.draft10.frame.Http2PriorityFrame;
/** /**
* An unmarshaller for {@link Http2PriorityFrame} instances. * An unmarshaller for {@link Http2PriorityFrame} instances.

View File

@ -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.Http2Flags;
import io.netty.handler.codec.http2.draft10.frame.Http2Frame; 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.Http2FrameHeader;
import io.netty.handler.codec.http2.draft10.frame.Http2PushPromiseFrame;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;

View File

@ -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.DefaultHttp2RstStreamFrame;
import io.netty.handler.codec.http2.draft10.frame.Http2Frame; 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.Http2FrameHeader;
import io.netty.handler.codec.http2.draft10.frame.Http2RstStreamFrame;
/** /**
* An unmarshaller for {@link Http2RstStreamFrame} instances. * An unmarshaller for {@link Http2RstStreamFrame} instances.

View File

@ -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.DefaultHttp2SettingsFrame;
import io.netty.handler.codec.http2.draft10.frame.Http2Frame; 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.Http2FrameHeader;
import io.netty.handler.codec.http2.draft10.frame.Http2SettingsFrame;
/** /**
* An unmarshaller for {@link Http2SettingsFrame} instances. * An unmarshaller for {@link Http2SettingsFrame} instances.

View File

@ -30,8 +30,17 @@ import static io.netty.handler.codec.http2.draft10.frame.Http2FrameCodecUtil.FRA
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
import io.netty.handler.codec.http2.draft10.Http2Exception; 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.Http2Frame;
import io.netty.handler.codec.http2.draft10.frame.Http2FrameHeader; 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. * 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_GO_AWAY] = new Http2GoAwayFrameUnmarshaller();
unmarshallers[FRAME_TYPE_WINDOW_UPDATE] = new Http2WindowUpdateFrameUnmarshaller(); unmarshallers[FRAME_TYPE_WINDOW_UPDATE] = new Http2WindowUpdateFrameUnmarshaller();
unmarshallers[FRAME_TYPE_CONTINUATION] = new Http2FrameUnmarshaller() { 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 @Override
public Http2FrameUnmarshaller unmarshall(Http2FrameHeader header) throws Http2Exception { public Http2FrameUnmarshaller unmarshall(Http2FrameHeader header) throws Http2Exception {
throw protocolError(msg); throw protocolError(MSG);
} }
@Override @Override
public Http2Frame from(ByteBuf payload, ByteBufAllocator alloc) throws Http2Exception { public Http2Frame from(ByteBuf payload, ByteBufAllocator alloc) throws Http2Exception {
throw protocolError(msg); throw protocolError(MSG);
} }
}; };
} }

View File

@ -37,7 +37,7 @@ public class DefaultHttp2HeadersEncoder implements Http2HeadersEncoder {
private final Encoder encoder; private final Encoder encoder;
public DefaultHttp2HeadersEncoder() { public DefaultHttp2HeadersEncoder() {
this.encoder = new Encoder(DEFAULT_HEADER_TABLE_SIZE); encoder = new Encoder(DEFAULT_HEADER_TABLE_SIZE);
} }
@Override @Override

View File

@ -56,7 +56,7 @@ public class Http2DataFrameMarshaller extends AbstractHttp2FrameMarshaller<Http2
out.writeZero(frame.getPaddingLength()); out.writeZero(frame.getPaddingLength());
} }
private Http2Flags getFlags(Http2DataFrame frame) { private static Http2Flags getFlags(Http2DataFrame frame) {
short flags = 0; short flags = 0;
if (frame.isEndOfStream()) { if (frame.isEndOfStream()) {
flags |= FLAG_END_STREAM; flags |= FLAG_END_STREAM;

View File

@ -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. * 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 = ByteBuf fragment =
headerBlock.readSlice(Math.min(headerBlock.readableBytes(), MAX_FRAME_PAYLOAD_LENGTH)); headerBlock.readSlice(Math.min(headerBlock.readableBytes(), MAX_FRAME_PAYLOAD_LENGTH));

View File

@ -77,7 +77,7 @@ public class Http2PushPromiseFrameMarshaller extends
/** /**
* Writes a single continuation frame with a fragment of the header block to the output buffer. * 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 = ByteBuf fragment =
headerBlock.readSlice(Math.min(headerBlock.readableBytes(), MAX_FRAME_PAYLOAD_LENGTH)); headerBlock.readSlice(Math.min(headerBlock.readableBytes(), MAX_FRAME_PAYLOAD_LENGTH));

View File

@ -133,7 +133,7 @@ public class DefaultInboundFlowControllerTest {
verify(frameWriter).writeFrame(eq(windowUpdate(STREAM_ID, delta))); 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; int newWindowSize = windowSize - dataSize;
return initialSize - newWindowSize; return initialSize - newWindowSize;
} }
@ -151,7 +151,7 @@ public class DefaultInboundFlowControllerTest {
verify(frameWriter, never()).writeFrame(any(Http2WindowUpdateFrame.class)); 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) return new DefaultHttp2WindowUpdateFrame.Builder().setStreamId(streamId)
.setWindowSizeIncrement(delta).build(); .setWindowSizeIncrement(delta).build();
} }

View File

@ -236,7 +236,7 @@ public class DefaultOutboundFlowControllerTest {
frame.release(2); frame.release(2);
} }
private Http2DataFrame frame(int payloadLength) { private static Http2DataFrame frame(int payloadLength) {
ByteBuf buffer = Unpooled.buffer(payloadLength); ByteBuf buffer = Unpooled.buffer(payloadLength);
buffer.writerIndex(payloadLength); buffer.writerIndex(payloadLength);
return new DefaultHttp2DataFrame.Builder().setStreamId(STREAM_ID).setContent(buffer).build(); return new DefaultHttp2DataFrame.Builder().setStreamId(STREAM_ID).setContent(buffer).build();

View File

@ -256,7 +256,7 @@ public class Http2FrameRoundtripTest {
captureHandler.release(); captureHandler.release();
} }
private void assertAndReleaseFrames(Http2Frame in, Http2Frame out) { private static void assertAndReleaseFrames(Http2Frame in, Http2Frame out) {
assertEquals(in, out); assertEquals(in, out);
if (in instanceof ByteBufHolder) { if (in instanceof ByteBufHolder) {
assertEquals(1, ((ByteBufHolder) in).refCnt()); assertEquals(1, ((ByteBufHolder) in).refCnt());
@ -298,7 +298,7 @@ public class Http2FrameRoundtripTest {
holder.release(); holder.release();
} }
this.frame = (Http2Frame) msg; frame = (Http2Frame) msg;
count++; count++;
} }