Utilizing HTTP/2 server push
The HTTP/2 specification provides the server with the ability to push the resources, prior to being requested. This recipe shows you how to implement the server push.
Getting ready
Prepare the private key and self-signed X-509 certificate. For this purpose, the openssl
utility could be used. By executing the command openssl genrsa -out server.key 2048
, the private key derived with the use of the RSA algorithm is generated to file, server.key
. Based on this private key, the X-509 certificate could be generated by calling openssl req -new -x509 -sha256 -key server.key -out server.crt -days 365
. The server.crt
file is created.
How to do it...
- Open the console and create the folder
chapter11/recipe09
. - Navigate to the directory.
- Create the file
push.go
with the following content:
package main import ( "io" "log" "net/http" ) func main() { log.Println("Staring server...") // Adding to mani...