19

After some research, I was surprised that I did not not find any resource on HTTP/2 support in Tomcat. Changelogs of 8.0 indicate an experimental support of SPDY and wiki refers to HTTP/2 as a supported spec (http://wiki.apache.org/tomcat/Specifications) but I don't find any tutorial on it.

Do you know if it is already possible to enable HTTP/2 on Tomcat? If the answer is yes how I can do that?

Thunderforge
  • 19,637
  • 18
  • 83
  • 130
Guillaume D.
  • 3,284
  • 3
  • 20
  • 26

4 Answers4

21

Tomcat does not yet support HTTP/2.

HTTP/2 support is planned for Tomcat 9 onwards. It may get back-ported to earlier versions.

The experimental SPDY support was just that: experimental. It worked while the browsers supported the particular version of SPDY but no browser currently supports the version of SDPY implemented by Tomcat.

That experimental support of SPDY has been removed from Tomcat 8.0.22, noted in the changelog.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
Mark Thomas
  • 16,339
  • 1
  • 39
  • 60
11

Tomcat 8.5 has been released with features back-ported from Tomcat 9 and includes HTTP/2 support.

I haven't personally had the chance to setup HTTP/2 on Tomcat 8.5 yet, so I can't comment on the "how to".

Joe Aldrich
  • 491
  • 4
  • 8
8

HTTP/2 Support is now available in Tomcat. Tomcat-8.5 supports HTTP/2. To enable HTTP/2 in tomcat-8.5 or above you need to upgrade the connector protocol in the file server.xml in the tomcat conf folder.

<Connector ... >
  <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
</Connector>

You also need to set up the configuration of your SSL certificates to work with this connector.

Chic
  • 9,836
  • 4
  • 33
  • 62
Dhumil Agarwal
  • 856
  • 2
  • 11
  • 19
  • 1
    Thanks! How do you perform server-push? – Guillaume D. Jul 10 '16 at 09:00
  • Server Push can be performed using PushBuilder API in Java. – Dhumil Agarwal Jul 11 '16 at 10:03
  • So does it means that there is no native API that can be used and consequently servlet 4 is required? Also if this statement is true we can take advantage from server-push only in tomcat 9 because it seems that tomcat 8.5 still use servlet 3.1? – Guillaume D. Jul 11 '16 at 10:15
  • To add to the answer about configuring Tomcat 9 for HTTP/2 see this: https://readlearncode.com/configure-tomcat-9-for-http2/ – Alex Theedom Jul 16 '16 at 10:03
  • HTTP/2 by default is made secure by design. Hence, we need to have SSL with HTTP2. If you do not want to have SSL, then you need to go back to HTTP 1.1 and cannot use HTTP2. – Dhumil Agarwal Oct 28 '19 at 08:54
1

to enable http2 for tomcat8.5.x,

@Bean
       public EmbeddedServletContainerCustomizer tomcatCustomizer() {
        return container -> {
            if (container instanceof TomcatEmbeddedServletContainerFactory) {
                ((TomcatEmbeddedServletContainerFactory) container).addConnectorCustomizers((connector) -> {
                    connector.addUpgradeProtocol(new Http2Protocol());
                });
            }
        };
    }
sapna
  • 161
  • 1
  • 4