use of com.linkedin.r2.message.stream.StreamResponseBuilder in project rest.li by linkedin.
the class ClientEntityStreamHandler method channelRead.
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
if (msg instanceof StreamResponseBuilder) {
final StreamResponseBuilder builder = (StreamResponseBuilder) msg;
final Map<String, String> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
headers.putAll(builder.getHeaders());
final Map<String, String> wireAttrs = WireAttributeHelper.removeWireAttributes(headers);
final StreamWriter writer = new StreamWriter(ctx, _maxContentLength);
ctx.channel().attr(NettyChannelAttributes.RESPONSE_WRITER).set(writer);
final StreamResponse response = builder.unsafeSetHeaders(headers).build(EntityStreams.newEntityStream(writer));
final TransportCallback<StreamResponse> callback = ctx.channel().attr(NettyChannelAttributes.RESPONSE_CALLBACK).getAndSet(null);
if (callback != null) {
callback.onResponse(TransportResponseImpl.success(response, wireAttrs));
}
} else if (msg instanceof ByteString) {
final StreamWriter writer = msg == StreamWriter.EOF ? ctx.channel().attr(NettyChannelAttributes.RESPONSE_WRITER).getAndSet(null) : ctx.channel().attr(NettyChannelAttributes.RESPONSE_WRITER).get();
if (writer != null) {
writer.onDataAvailable((ByteString) msg);
}
} else {
ctx.fireChannelRead(msg);
}
}
Aggregations