Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update plugin interceptor examples. #173

Merged
merged 8 commits into from
May 30, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.HttpClientCodec;
import io.netty.handler.codec.http.HttpContentDecompressor;
import io.netty.handler.logging.LoggingHandler;
import io.netty.handler.ssl.SslContext;
import rx.Observable;

Expand Down Expand Up @@ -106,6 +107,8 @@ private class Initializer extends ChannelInitializer<Channel> {
protected void initChannel(Channel ch) {
ChannelPipeline pipeline = ch.pipeline();

pipeline.addLast("logging-handler-1", new LoggingHandler());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why -1 and -2? The names should explain why we need two.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these pushed accidentally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some instrumentation hoping to replicate a CI test failure.

Backing this off.


if (sslContext != null) {
pipeline.addLast("ssl", sslContext.newHandler(ch.alloc()));
}
Expand All @@ -114,6 +117,8 @@ protected void initChannel(Channel ch) {
if (httpConfig.compress()) {
pipeline.addLast("decompressor", new HttpContentDecompressor());
}

pipeline.addLast("logging-handler-2", new LoggingHandler());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,12 @@ private void scheduleResourcesTearDown(ChannelHandlerContext ctx) {
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
ensureContentProducerIsCreated(ctx);

LOGGER.warn("channelRead0: {}", msg);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this pushed accidentally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes


if (msg instanceof io.netty.handler.codec.http.HttpResponse) {
io.netty.handler.codec.http.HttpResponse nettyResponse = (io.netty.handler.codec.http.HttpResponse) msg;
if (nettyResponse.getDecoderResult().isFailure()) {
LOGGER.warn("Http Response Failure. ", nettyResponse.decoderResult());
emitResponseError(new BadHttpResponseException(origin, nettyResponse.getDecoderResult().cause()));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.DefaultHttpContent;
import io.netty.handler.codec.http.HttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import rx.Subscriber;
Expand All @@ -32,7 +33,6 @@
import java.util.concurrent.atomic.AtomicLong;

import static com.hotels.styx.api.StyxInternalObservables.toRxObservable;
import static io.netty.handler.codec.http.HttpHeaders.setTransferEncodingChunked;
import static io.netty.handler.codec.http.LastHttpContent.EMPTY_LAST_CONTENT;
import static java.util.Objects.requireNonNull;

Expand Down Expand Up @@ -154,7 +154,7 @@ private void completeIfAllSent(CompletableFuture<Void> future) {
private ChannelFuture writeHeaders(HttpResponse response) {
io.netty.handler.codec.http.HttpResponse nettyResponse = responseTranslator.toNettyResponse(response);
if (!(response.contentLength().isPresent() || response.chunked())) {
setTransferEncodingChunked(nettyResponse);
HttpUtil.setTransferEncodingChunked(nettyResponse, true);
}

return nettyWriteAndFlush(nettyResponse);
Expand Down
Loading