I am trying to use netty to write some HTTP application. But I am confused by the so many similar types:
I guess I lack an understanding of netty's design philosophy behind this.
Could anyone shed some light?
When an HTTP message is decoded by an HttpObjectDecoder, the decoder produces the following objects:
HttpRequest or an HttpResponse that provides the properties decoded from the initial line and its following headers.HttpContent. The last HttpContent is LastHttpContent.A typical handler code will look like the following:
if (msg instanceof HttpRequest) {
...
}
if (msg instanceof HttpContent) {
...
if (msg instanceof LastHttpContent) {
...
}
}
Please note that the if blocks are not mutually exclusive and thus the handler does not return when one of the 3 conditions above is met. Take a look into HttpSnoopServerHandler for a concrete example.
Now, let's take a look at FullHttpRequest. It implements HttpRequest, HttpContent, and LastHttpContent. The well-written handler should just work when we inserted HttpObjectAggregator into the pipeline without changing any code.
So, the intention of this weird-looking class hierarchy is to enable a user to choose to use HttpObjectAggregator or not.
However, I do agree this is not intuitive. We are going to fix this in Netty 5 in such a way that the decoder produces only a single HTTP message object and streaming its content to it later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With