Skip to content

Experimental HTTP 2 Support

Santiago Pericasgeertsen edited this page Oct 17, 2018 · 9 revisions

Introduction

Helidon 0.10.3 has experimental support for HTTP/2. This feature is turned off by default but can be enabled in an application's configuration. Enabling HTTP/2 will automatically accept, on every endpoint exposed by the application:

  1. Clients sending upgrade requests for HTTP/2
  2. Clients connecting via HTTP/2 with prior knowledge
  3. Clients sending HTTP 1.X requests

Note that in (1) the initial request is HTTP 1.X but the response, as well as every subsequent exchange, is in HTTP/2 --assuming the upgrade process is successful.

Enabling HTTP/2 Support

Experimental support for HTTP/2 is enabled in the experimental section as shown next:

server:
  port: 8080
  host: 0.0.0.0
  experimental:
    http2:
      enable: true
      max-content-length: 16384

The property enable under http2 is set to true to enable the feature. There is currently no support for content streaming using HTTP/2, so the property max-content-length can be set to the maximum payload length in bytes for any request/response in the application (the default value is 64K).

Testing HTTP/2 Using Curl

Recent versions of the popular curl command have support for HTTP/2. The following example shows how to initiate a request for an HTTP/2 upgrade:

curl --http2 http://localhost:8080/greet/Santiago

The -v (verbose) option can be used to confirm the upgrade. If prior knowledge is available that an endpoint supports HTTP/2, then the upgrade can be bypassed as follows:

curl --http2-prior-knowledge http://localhost:8080/greet/Santiago

Finally, you can verify the use of a single HTTP/2 connection for multiple requests by simply passing more than one URL as a parameter:

URL=http://localhost:8080/greet/Santiago
curl --http2-prior-knowledge $URL $URL $URL

In HTTP 1.X terms, all HTTP/2 connections are always keep-alive enabled.