use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpResponse in project jocean-http by isdom.
the class TestHttpUtil method buildBytesResponse.
public static Observable<HttpObject> buildBytesResponse(final String contentType, final byte[] content) {
final FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, OK, Unpooled.wrappedBuffer(content));
response.headers().set(HttpHeaderNames.CONTENT_TYPE, contentType);
response.headers().set(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes());
return Observable.<HttpObject>just(response);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpResponse in project jocean-http by isdom.
the class DefaultHttpClientTestCase method testInitiatorInteractionClientCanceledAsHttp.
@Test(timeout = 5000)
public void testInitiatorInteractionClientCanceledAsHttp() throws Exception {
// 配置 池化分配器 为 取消缓存,使用 Heap
configDefaultAllocator();
final PooledByteBufAllocator allocator = defaultAllocator();
final BlockingQueue<HttpTrade> trades = new ArrayBlockingQueue<>(1);
final String addr = UUID.randomUUID().toString();
final Subscription server = TestHttpUtil.createTestServerWith(addr, trades, Feature.ENABLE_LOGGING);
final DefaultHttpClient client = new DefaultHttpClient(new TestChannelCreator(), Feature.ENABLE_LOGGING);
assertEquals(0, allActiveAllocationsCount(allocator));
try {
startInteraction(client.initiator().remoteAddress(new LocalAddress(addr)), Observable.just(fullHttpRequest()), new Interaction() {
@Override
public void interact(final HttpInitiator initiator, final Observable<DisposableWrapper<FullHttpResponse>> getresp) throws Exception {
final TestSubscriber<DisposableWrapper<FullHttpResponse>> subscriber = new TestSubscriber<>();
final Subscription subscription = getresp.subscribe(subscriber);
// server side recv req
final HttpTrade trade = trades.take();
// recv request from client side
trade.inbound().doOnNext(DISPOSE_EACH).toCompletable().await();
// server not send response, and client cancel this interaction
subscription.unsubscribe();
TerminateAware.Util.awaitTerminated(trade);
TerminateAware.Util.awaitTerminated(initiator);
assertTrue(!initiator.isActive());
subscriber.assertNoTerminalEvent();
subscriber.assertNoValues();
}
});
assertEquals(0, allActiveAllocationsCount(allocator));
} finally {
client.close();
server.unsubscribe();
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpResponse in project jocean-http by isdom.
the class Nettys method httpobjs2fullresp.
// retain when build fullresp
public static FullHttpResponse httpobjs2fullresp(final List<HttpObject> httpobjs) {
if (httpobjs.size() > 0 && (httpobjs.get(0) instanceof HttpResponse) && (httpobjs.get(httpobjs.size() - 1) instanceof LastHttpContent)) {
if (httpobjs.get(0) instanceof FullHttpResponse) {
return ((FullHttpResponse) httpobjs.get(0)).retainedDuplicate();
}
final HttpResponse resp = (HttpResponse) httpobjs.get(0);
final DefaultFullHttpResponse fullresp = new DefaultFullHttpResponse(resp.protocolVersion(), resp.status(), tobuf(httpobjs));
fullresp.headers().add(resp.headers());
// ? need update Content-Length header field ?
return fullresp;
} else {
throw new RuntimeException("invalid HttpObjects");
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpResponse in project ratpack by ratpack.
the class ContentAggregatingRequestAction method addResponseHandlers.
@Override
protected void addResponseHandlers(ChannelPipeline p, Downstream<? super ReceivedResponse> downstream) {
p.addLast(AGGREGATOR_HANDLER_NAME, new NoContentLengthOnNoBodyHttpObjectAggregator(requestConfig.maxContentLength));
p.addLast(RESPONSE_HANDLER_NAME, new SimpleChannelInboundHandler<FullHttpResponse>(false) {
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpResponse response) throws Exception {
response.touch();
dispose(ctx.pipeline(), response);
ByteBuf content = new ByteBufRef(response.content());
execution.onComplete(() -> {
if (content.refCnt() > 0) {
content.release();
}
});
success(downstream, toReceivedResponse(response, content));
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
cause = decorateException(cause);
error(downstream, cause);
forceDispose(ctx.pipeline());
}
});
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpResponse in project cdap by caskdata.
the class HttpRequestRouter method createPipeliningNotSupported.
private HttpResponse createPipeliningNotSupported() {
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_IMPLEMENTED);
response.content().writeCharSequence("HTTP pipelining is not supported", StandardCharsets.UTF_8);
HttpUtil.setContentLength(response, response.content().readableBytes());
return response;
}
Aggregations