use of 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 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 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;
}
use of io.netty.handler.codec.http.FullHttpResponse in project sidewinder by srotya.
the class HTTPDataPointDecoder method writeResponse.
private boolean writeResponse(HttpObject httpObject, ChannelHandlerContext ctx) {
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, httpObject.decoderResult().isSuccess() ? OK : BAD_REQUEST, Unpooled.copiedBuffer(responseString.toString().toString(), CharsetUtil.UTF_8));
response.headers().set(CONTENT_TYPE, "text/plain; charset=UTF-8");
response.headers().set(CONTENT_LENGTH, response.content().readableBytes());
response.headers().set(CONNECTION, HttpHeaderValues.KEEP_ALIVE);
responseString = new StringBuilder();
// Write the response.
ctx.write(response);
return true;
}
use of io.netty.handler.codec.http.FullHttpResponse in project sidewinder by srotya.
the class HTTPDataPointDecoder method send100Continue.
private static void send100Continue(ChannelHandlerContext ctx) {
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, CONTINUE);
ctx.write(response);
}
Aggregations