I just announced the new Learn Spring course, focused on the fundamentals of Spring 5 and Spring Boot 2:

1. Overview

Netty is an NIO-based client-server framework that gives Java developers the power to operate on the network layers. Using this framework, developers can build their own implementation of any known protocol, or even custom protocols.

2. What is HTTP/2?

Around the year 1989, when the internet was born, HTTP/1.0 came into being. In 1997, it was upgraded to version 1.1. However, it wasn't until 2015 that it saw a major upgrade, version 2.

As of writing this, HTTP/3 is also available, though not yet supported by default by all browsers.

HTTP/2 is still the latest version of the protocol that is widely accepted and implemented. It differs significantly from the previous versions with its multiplexing and server push features, among other things.

Communication in HTTP/2 happens via a group of bytes called frames, and multiple frames form a stream.

In our code samples, we'll see how Netty handles the exchange of HEADERS, DATA and SETTINGS frames.

As we can see, it's pretty much similar to the server's SslContext, just that we are not providing any SelfSignedCertificate here. Another difference is that we are adding an InsecureTrustManagerFactory to trust any certificate without any verification.

Importantly, this trust manager is purely for demo purposes and should not be used in production. To use trusted certificates instead, Netty's SslContextBuilder offers many alternatives.

At the end of the method, we flag the ChannelPromise as successful to indicate proper completion.

As the first handler we described, this class also contains a utility method for our client's use. The method makes our event loop wait until the ChannelPromise is successful. Or, in other words, it waits till the response processing is complete:

As the article mentions, Netty supports APN negotiation for HTTP/2 over TLS. To send HTTP2 request without SSL, you need to use the Upgrade mechanism via HTTP/1.1 Upgrade using the h2c identifier as used here.