Two lines open go HTTP quic

Source: Internet
Author: User
Tags quic
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.