Search in sources :

Example 51 with DefaultFullHttpResponse

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpResponse 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);
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpObject(io.netty.handler.codec.http.HttpObject) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse)

Example 52 with DefaultFullHttpResponse

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpResponse 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");
    }
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) LastHttpContent(io.netty.handler.codec.http.LastHttpContent)

Example 53 with DefaultFullHttpResponse

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpResponse in project jocean-http by isdom.

the class RxNettys method response404NOTFOUND.

public static Observable<HttpObject> response404NOTFOUND(final HttpVersion version) {
    final HttpResponse response = new DefaultFullHttpResponse(version, HttpResponseStatus.NOT_FOUND);
    response.headers().set(HttpHeaderNames.CONTENT_LENGTH, 0);
    return Observable.<HttpObject>just(response);
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpObject(io.netty.handler.codec.http.HttpObject) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse)

Example 54 with DefaultFullHttpResponse

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpResponse 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;
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse)

Example 55 with DefaultFullHttpResponse

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpResponse in project cdap by caskdata.

the class AuthenticationChannelHandler method exceptionCaught.

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    LOG.error("Got exception: {}", cause.getMessage(), cause);
    // TODO: add WWW-Authenticate header for 401 response -  REACTOR-900
    HttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.UNAUTHORIZED);
    HttpUtil.setContentLength(response, 0);
    HttpUtil.setKeepAlive(response, false);
    ctx.channel().writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse)

Aggregations

DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)223 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)145 ByteBuf (io.netty.buffer.ByteBuf)68 HttpResponse (io.netty.handler.codec.http.HttpResponse)39 Test (org.junit.Test)25 HttpRequest (io.netty.handler.codec.http.HttpRequest)24 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)23 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)22 ChannelFuture (io.netty.channel.ChannelFuture)19 IOException (java.io.IOException)19 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)16 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)16 DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)15 HttpObject (io.netty.handler.codec.http.HttpObject)15 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)12 HttpVersion (io.netty.handler.codec.http.HttpVersion)12 InetSocketAddress (java.net.InetSocketAddress)12 SSLException (javax.net.ssl.SSLException)12 Test (org.junit.jupiter.api.Test)12 Map (java.util.Map)11