Jonathan Beaudoin
Jonathan Beaudoin

Reputation: 2188

Convert This Netty 3 Code To Netty 4

I've been trying to upgrade this block of code to Netty 4.

    HttpResponse resp = new DefaultFullHttpResponse(request.getProtocolVersion(), status);

    resp.headers().set("Date", new Date());
    resp.headers().set("Server", SERVER_IDENTIFIER);
    resp.headers().set("Content-type", mimeType + ", charset=" + CHARACTER_SET.name());
    resp.headers().set("Cache-control", "no-cache");
    resp.headers().set("Pragma", "no-cache");
    resp.headers().set("Expires", new Date(0));
    resp.headers().set("Connection", "close");
    resp.headers().set("Content-length", wrappedBuf.readableBytes());
    resp.setChunked(false);
    resp.setContent(wrappedBuf);

I've done everything but could someone tell me what these lines should be in Netty 4?

    resp.setChunked(false);
    resp.setContent(wrappedBuf);

Thanks!

Upvotes: 2

Views: 270

Answers (1)

Norman Maurer
Norman Maurer

Reputation: 23557

Just inject the wrappedBuf directly via the constructor:

FullHttpResponse resp = new DefaultFullHttpResponse(..., wrappedBuf);

You can ignore the setChunked(...) stuff

Upvotes: 2

Related Questions