1 year ago

#129451

test-img

MCCCS

cannot connect to quic-go http 3

package main

import (
    "github.com/lucas-clemente/quic-go"
    "github.com/lucas-clemente/quic-go/http3"
    "log"
    "net/http"
)

const KPORT = ":1441"

const KCERT = "./example.com+5.pem"
const KKEY = "./example.com+5-key.pem"
const KHTTP3 = true

func main() {
    mux := http.NewServeMux()

    mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
        w.Write([]byte(
            `<!DOCTYPE html>
      <html lang="en">
      <head></head>
      <body>
      hello
      </body>
      </html>
      `,
        ))
    })

    srv := &http.Server{
        Addr:    KPORT,
        Handler: mux,
    }

    if !KHTTP3 {
        log.Fatal(srv.ListenAndServeTLS(
            KCERT,
            KKEY,
        ))
    } else {
        qconf := quic.Config{}
        // https://github.com/lucas-clemente/quic-go/blob/master/example/main.go#L187
        quicServer := http3.Server{
            Server:     srv,
            QuicConfig: &qconf,
        }
        log.Fatal(quicServer.ListenAndServeTLS(
            KCERT,
            KKEY,
        ))
    }
}

KHTTP3 toggles HTTP3 quic package quic-go above. When I enable KHTTP3 and try to connect, the browser behaves as if I didn't start any Go server. No error messages anywhere. What is wrong with my code? I tried to stick to the example at https://github.com/lucas-clemente/quic-go/blob/master/example/main.go#L187

EDIT: My new code that works well, suggested by mh-cbon is:

        log.Fatal(http3.ListenAndServe(
            KPORT,
            KCERT,
            KKEY,
            mux,
        ))

go

quic

http3

0 Answers

Your Answer

Accepted video resources