This is a creation in Article, where the information may have evolved or changed.
QUIC, in short, is the use of UDP transmission protocol, according to Google's own report, speed can be increased by 30%. The main advantages are:
1. 快速建立链接(不用3次握手和TLS4次握手)2. 多路复用3. 改进的流控4. 快速SSL/TLS握手5. 适合移动用户访问
Such a good performance, of course, to hurry with go to try.
Https://github.com/lucas-clemente/quic-go
The code in the example is also simple.
http.Handle("/", http.FileServer(http.Dir(wwwDir)))h2quic.ListenAndServeQUIC("localhost:4242", "/path/to/cert/chain.pem", "/path/to/privkey.pem", nil)
In practice, however, 2 pits were encountered.
TLS configuration
Because my service is an HTTP. Handler, so Quic need to reconfigure tlsconfig, otherwise it will be an error. Here is the sample code
quic := &h2quic.Server{Server: server}quic.TLSConfig = &tls.Config{}quic.TLSConfig.GetCertificate = getCertificatepln, err := net.ListenPacket("udp", cfg.Listen)if err != nil { log.Fatal(err)}log.Print("listen quic on udp:%s", cfg.Listen)go quic.Serve(pln)
Header settings
When successfully enabled, the Spdy plugin in Chrome doesn't have a green flag or continues to use HTTP2, and after finding it, Google has added a
writer.ResponseWriter.Header().Add("alt-svc", `quic=":443"; ma=2592000; v="38,37,36"`)
which
- Ma is the expiration time in seconds
- V refers to supported Quic versions
- ALT-SVC is Alternative-service's abbreviation.
- Quic is the port of Quic, I have specified 443
Finally, by typing in the Chrome address bar
chrome://net-internals/#quic