Skip to content

Commit

Permalink
HTTP/2 Server Example Not Using Flow Controller
Browse files Browse the repository at this point in the history
Motiviation:
The HTTP/2 server example is not using the outbound flow control.  It is instead using a FrameWriter directly.
This can lead to flow control errors and other comm. related errors

Modifications:
-Force server example to use outbound flow controller

Result:
-Server example should use follow flow control rules.
  • Loading branch information
Scottmitch authored and normanmaurer committed Oct 13, 2014
1 parent ad259a4 commit c8c69ae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,10 @@ public Http2ConnectionHandler(Http2Connection connection, Http2FrameReader frame
public Http2ConnectionHandler(Http2Connection connection, Http2FrameReader frameReader,
Http2FrameWriter frameWriter, Http2InboundFlowController inboundFlow,
Http2OutboundFlowController outboundFlow, Http2FrameListener listener) {
this.encoder =
DefaultHttp2ConnectionEncoder.newBuilder().connection(connection)
.frameWriter(frameWriter).outboundFlow(outboundFlow).lifecycleManager(this)
.build();
this.decoder =
DefaultHttp2ConnectionDecoder.newBuilder().connection(connection)
.frameReader(frameReader).inboundFlow(inboundFlow).encoder(encoder)
.listener(listener).lifecycleManager(this).build();
clientPrefaceString = clientPrefaceString(connection);
this(DefaultHttp2ConnectionDecoder.newBuilder().connection(connection)
.frameReader(frameReader).inboundFlow(inboundFlow).listener(listener),
DefaultHttp2ConnectionEncoder.newBuilder().connection(connection)
.frameWriter(frameWriter).outboundFlow(outboundFlow));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.netty.handler.codec.http2.DefaultHttp2FrameWriter;
import io.netty.handler.codec.http2.DefaultHttp2Headers;
import io.netty.handler.codec.http2.Http2Connection;
import io.netty.handler.codec.http2.Http2ConnectionEncoder;
import io.netty.handler.codec.http2.Http2ConnectionHandler;
import io.netty.handler.codec.http2.Http2Exception;
import io.netty.handler.codec.http2.Http2FrameAdapter;
Expand All @@ -52,12 +53,13 @@ public class HelloWorldHttp2Handler extends Http2ConnectionHandler {
public HelloWorldHttp2Handler() {
this(new DefaultHttp2Connection(true), new Http2InboundFrameLogger(
new DefaultHttp2FrameReader(), logger), new Http2OutboundFrameLogger(
new DefaultHttp2FrameWriter(), logger));
new DefaultHttp2FrameWriter(), logger), new SimpleHttp2FrameListener());
}

private HelloWorldHttp2Handler(Http2Connection connection, Http2FrameReader frameReader,
Http2FrameWriter frameWriter) {
super(connection, frameReader, frameWriter, new SimpleHttp2FrameListener(frameWriter));
Http2FrameWriter frameWriter, SimpleHttp2FrameListener listener) {
super(connection, frameReader, frameWriter, listener);
listener.encoder(encoder());
}

/**
Expand All @@ -83,10 +85,10 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
}

private static class SimpleHttp2FrameListener extends Http2FrameAdapter {
private Http2FrameWriter frameWriter;
private Http2ConnectionEncoder encoder;

public SimpleHttp2FrameListener(Http2FrameWriter frameWriter) {
this.frameWriter = frameWriter;
public void encoder(Http2ConnectionEncoder encoder) {
this.encoder = encoder;
}

/**
Expand Down Expand Up @@ -118,8 +120,8 @@ public void onHeadersRead(ChannelHandlerContext ctx, int streamId,
private void sendResponse(ChannelHandlerContext ctx, int streamId, ByteBuf payload) {
// Send a frame for the response status
Http2Headers headers = new DefaultHttp2Headers().status(new AsciiString("200"));
frameWriter.writeHeaders(ctx, streamId, headers, 0, false, ctx.newPromise());
frameWriter.writeData(ctx, streamId, payload, 0, true, ctx.newPromise());
encoder.writeHeaders(ctx, streamId, headers, 0, false, ctx.newPromise());
encoder.writeData(ctx, streamId, payload, 0, true, ctx.newPromise());
ctx.flush();
}
};
Expand Down

0 comments on commit c8c69ae

Please sign in to comment.