Technology: HTTP2 is the major release of the HTTP network protocol used by WWW (world wide web). It is the recent new version of HTTP Protocol as HTTP 1.1 was released in 1997. It was derived from SPDY protocol, originally developed by Google. All the major browsers like Chrome, Opera, Firefox, Safari, Edge browsers are supporting this protocol.
Advantages of HTTP2 over HTTP1.1
1. Multiplexing and Concurrency: For rendering the one HTML it may need some JS, CSS, Images files need to get from server for better look and feel, if we use HTTP 1.1 protocol after getting the HTML response client will request for each JS, CSS, Image files separately, which needs the one TCP connection for each of the request which was very costly. It was improved in HTTP2 protocol, instead of the client is requesting for several resources needed in a HTML Page, a server will push the response to the client so that with single TCP connection all content needed will be available to a client. This allows the server to supply the data needed for a web browser to render a web page without waiting for the first responders.
Add paragraph text here.
2. Stream Prioritization: The client can indicate which if the resources are more important than others to a server. For providing the prioritization HTTP2 standards has a feature to provide associated weight and dependency (if the stream is depending on another stream).
It also requires both server and client to maintain and update the indexed list of previously sent header fields which is then used as a reference to efficiently encode previously transmitted values. Huffman coding provides the specific values to be compressed when transferred, and the indexed list of before transferred values enables us to encode duplicate values by transferring index values that can be used to efficiently look up and rebuild the full header keys and values.
4. Server Push: The server will push all dependent resources which are not requested the client.
5. Flow Control: Flow control is the mechanism to prevent the sender from overwhelming with data to a receiver, it may not able to process the data because of many reasons like a receiver is busy, it is under heavy load, or it may not have allocated sufficient buffer space t process the data.
HTTP2 is addressing all these issues, by providing the receive window (rwnd), which communicates the size of transferring data between sender and receiver. When the connection is first established it will use default settings. If the server is streaming a large amount of data to a client in case of download client received window may become the limiting factor, similarly in case of the client send a large amount of data to the server, in this case, server receiving window will be limiting factor. In any case, a smaller window will be a limiting factor.
If the window reaches zero, it is considered as a hint that not sending more data without clearing the existing data in the buffer by app level. This workflow is available for every TCP Continues throughout the lifetime of the connection: Each ASK packet has the latest RW value for each side, dynamically switches data flow rates on the dynamics of the sender and receiver and the speed of the process.
HTTP/2 no longer supports HTTP 1.1's chunked shift encoding mechanism, as it gives its own, more effective, mechanisms for data streaming.
We will not need to change/update any of applications/API to work on HTTP2 properly, but our Java application development will work better and consume less resources on both client and server.
Enabling HTTP2 in Tomcat Server:
HTTP2 protocol is supported only after Tomcat 9 version.
Add below lines in conf/server.xml file:
<Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol" maxThreads="150" SSLEnabled="true">
<Certificate certificateKeyFile="conf/ca.key" certificateFile="conf/ca.crt"/>
Enable HTTP2 Support in Spring Boot:
You can allow HTTP2 in spring boot with the following property if the server has support for it.
Conclusion: In the current blog we learned what is HTTP2 protocol, what are advantages over HTTP1.1 and how to enable to Tomcat and Spring boot applications.
We just sent you an email. Please click the link in the email to confirm your subscription!
OKSubscriptions powered by Strikingly