use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse in project riposte by Nike-Inc.
the class ProcessFinalResponseOutputHandler method write.
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
// Deal with the final outbound HttpResponse
if (msg instanceof HttpResponse) {
HttpProcessingState state = ChannelAttributes.getHttpProcessingStateForChannel(ctx).get();
if (state != null)
state.setActualResponseObject((HttpResponse) msg);
}
// Deal with the final outbound body content
if (msg instanceof HttpContent) {
HttpProcessingState state = ChannelAttributes.getHttpProcessingStateForChannel(ctx).get();
if (state != null && state.getResponseInfo() != null) {
ResponseInfo<?> responseInfo = state.getResponseInfo();
long contentBytes = ((HttpContent) msg).content().readableBytes();
if (responseInfo.getFinalContentLength() == null)
responseInfo.setFinalContentLength(contentBytes);
else
responseInfo.setFinalContentLength(responseInfo.getFinalContentLength() + contentBytes);
}
}
super.write(ctx, msg, promise);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse in project riposte by Nike-Inc.
the class SmartHttpContentCompressor method write.
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
HttpProcessingState state = ChannelAttributes.getHttpProcessingStateForChannel(ctx).get();
allowCompressionForThisRequest = false;
if (state != null) {
// We only want to allow compression if the endpoint being hit is *not* a ProxyRouterEndpoint, the response is full, and the response size
// is greater than the threshold
boolean isFull = msg instanceof HttpResponse && msg instanceof LastHttpContent;
boolean endpointAllowed = endpointAllowsCompression(state.getEndpointForExecution());
boolean responseInfoAllowed = state.getResponseInfo() == null || !state.getResponseInfo().isPreventCompressedOutput();
if (isFull && endpointAllowed && responseInfoAllowed && ((LastHttpContent) msg).content().readableBytes() > responseSizeThresholdBytes) {
allowCompressionForThisRequest = true;
}
}
super.write(ctx, msg, promise);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse in project riposte by Nike-Inc.
the class ProcessFinalResponseOutputHandlerTest method write_calls_setActualResponseObject_on_state_if_msg_is_HttpResponse.
@Test
public void write_calls_setActualResponseObject_on_state_if_msg_is_HttpResponse() throws Exception {
// given
HttpResponse msgMock = mock(HttpResponse.class);
// when
handler.write(ctxMock, msgMock, promiseMock);
// then
verify(stateMock).setActualResponseObject(msgMock);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse in project riposte by Nike-Inc.
the class ProcessFinalResponseOutputHandlerTest method write_does_not_do_anything_with_state_if_msg_is_HttpResponse_but_state_is_null.
@Test
public void write_does_not_do_anything_with_state_if_msg_is_HttpResponse_but_state_is_null() throws Exception {
// given
HttpResponse msgMock = mock(HttpResponse.class);
doReturn(null).when(stateAttrMock).get();
// when
handler.write(ctxMock, msgMock, promiseMock);
// then
verifyNoMoreInteractions(stateMock);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponse in project apn-proxy by apn-proxy.
the class ApnProxyRemoteForwardHandler method channelRead.
public void channelRead(final ChannelHandlerContext remoteChannelCtx, final Object msg) throws Exception {
LoggerUtil.debug(logger, uaChannel.attr(ApnProxyConnectionAttribute.ATTRIBUTE_KEY), "Remote msg", msg);
remainMsgCount++;
if (remainMsgCount <= 5) {
remoteChannelCtx.read();
}
HttpObject ho = (HttpObject) msg;
if (ho instanceof HttpResponse) {
HttpResponse httpResponse = (HttpResponse) ho;
LoggerUtil.info(forwardRestLogger, uaChannel.attr(ApnProxyConnectionAttribute.ATTRIBUTE_KEY), httpResponse.getStatus(), httpResponse.getProtocolVersion());
httpResponse.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
httpResponse.headers().set("Proxy-Connection", HttpHeaders.Values.KEEP_ALIVE);
}
if (uaChannel.isActive()) {
uaChannel.writeAndFlush(ho).addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
LoggerUtil.debug(logger, uaChannel.attr(ApnProxyConnectionAttribute.ATTRIBUTE_KEY), "Write to UA finished: " + future.isSuccess());
if (future.isSuccess()) {
remainMsgCount--;
remoteChannelCtx.read();
LoggerUtil.debug(logger, uaChannel.attr(ApnProxyConnectionAttribute.ATTRIBUTE_KEY), "Fire read again");
} else {
remoteChannelCtx.close();
}
}
});
} else {
remoteChannelCtx.close();
}
}
Aggregations