An HTTP/2 server may send responses to a client without waiting for the request.
This is typically used in Web page scenarios: If a server receives a request to
Instead of waiting for these requests, the server may proactively create push requests for these resources,
and send responses immediately.
Push Echo Servlet Demo
As a demo, I created a push echo Servlet, which can be downloaded and built as follows:
In order to run it, you need to find out the correct ALPN version for your JDK
(see table 14.1), and download the ALPN boot JAR from Maven Central.
Given the correct
<path-to-alpn-boot.jar>, run the demo as follows:
The demo is an echo Servlet: You can POST data to
/data, and then GET that data from
However, the GET request is implemented as a Server Push. The GET request does not perform actual network traffic, because the response is already available on the client.
Using the h2c command line client, the demo can be run as follows:
In one terminal, run
h2c start --dump.
In another terminal, run
The GET request will return the message
I received the following data: hello world.
In the other h2c terminal, the dumped traffic shows that the GET request is never sent, because it is anticipated by the server as a PUSH_PROMISE.
h2c push-list, you can view which paths are currently available as pushed responses on the client.
Once a path is fetched with
h2c get, the pused path is will be removed from the list.
The commands above will show the path
/data, meaning that the next GET request to
/data will be responded locally with the available push response.