Tuesday, February 28, 2017

HTTP2 Support in Tomcat

From Tomcat version 9 on wards the server support http2
Http2 protocol works only on the ssl pages and hence need to enable ssl in tomcat first via doing the following steps
Create the ssl certificate openssl req -x509 -nodes -days 1095 -newkey rsa:2048 -out ../conf/localhost.crt -keyout ../conf/localhost.key -config ../conf/openssl.cnf
Add the following session in the server.xml file
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
               maxThreads="150" SSLEnabled="true" >
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
        <SSLHostConfig>
            <Certificate certificateKeyFile="conf/certificate/localhost.key"
                         certificateFile="conf/certificate/localhost.crt"
                          type="RSA" />
        </SSLHostConfig>
    </Connector>
Restart the server and go to https://localhost:8443/ the protocol used is http2
To check whether the server is returning back using http2 the following methods can be applied
  • Go to the tomcat's access log file and you can see "GET / HTTP/2.0" 200
  • Open chrom's developer tool and right click on the header and select protocol as well in the network tab. The protocol column shows h2 instead of http/1.1 

  • Install the chrome http2/SPDY plugin to check whether the site supports http2

No comments:

Post a Comment