Fully working Jetty HTTP2 example using Javalin
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 12 commits ahead of wmacgyver:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
gradle/wrapper
readme
src/main
.gitignore
README.md
build.gradle
gradlew
gradlew.bat

README.md

A fully working HTTP2 example with Jetty and Javalin

Javalin will run on any embedded Jetty server, and Jetty supports HTTP2 (with a few additional dependencies). This guide explains how to set it all up.

The example includes a generated keystore, but you'll need to generate your own if you intended to use this for anything:

  • Open a command prompt in the same directory as Java keytool and run:
  • keytool -genkey -alias mydomain -keyalg RSA -keystore keystore.jks -keysize 2048

The example uses Conscrypt as the SSL provider, which is recommended by Jetty.

The ALPN API version you need to use is specific to your JDK version. Find your correct version in the Jetty docs

The example has a HTTP1.1 connector on port 8080 and HTTP2 connector on 8443 (with fallback to SSL HTTP 1.1).

To verify that everything is working, open Chrome (or your browser of choice), go to https://localhost:8443, and open the network tab in the devtols. You should see "h2" in the "Protocol" column.

If you go to /static-files-test.html, open the Network tab and set your emulated network to 3G, you'll notice the difference:

HTTP1.1

http1

HTTP2

http2