quic_enabled.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. //go:build linux || freebsd || windows || netbsd || darwin
  2. // +build linux freebsd windows netbsd darwin
  3. package engine
  4. import (
  5. "net/http"
  6. "sync"
  7. "github.com/quic-go/quic-go/http3"
  8. log "github.com/sirupsen/logrus"
  9. )
  10. var quicEnabled = true
  11. // ListenAndServeQUIC attempts to serve the given http.Handler over QUIC/HTTP3,
  12. // then reports back any errors when done serving.
  13. func (ac *Config) ListenAndServeQUIC(mux http.Handler, mut *sync.Mutex, justServeRegularHTTP chan bool, servingHTTPS *bool) {
  14. // TODO: Handle ctrl-c by fetching the quicServer struct and passing it to GenerateShutdownFunction.
  15. // This can be done once CloseGracefully in h2quic has been implemented:
  16. // https://github.com/lucas-clemente/quic-go/blob/master/h2quic/server.go#L257
  17. // TODO: As far as I can tell, this was never implemented. Look into implementing this for github.com/xyproto/quic
  18. //
  19. // gracefulServer.ShutdownInitiated = ac.GenerateShutdownFunction(nil, quicServer)
  20. if err := http3.ListenAndServe(ac.serverAddr, ac.serverCert, ac.serverKey, mux); err != nil {
  21. log.Error("Not serving QUIC after all. Error: ", err)
  22. log.Info("Use the -t flag for serving regular HTTP instead")
  23. // If QUIC failed (perhaps the key + cert are missing),
  24. // serve plain HTTP instead
  25. justServeRegularHTTP <- true
  26. mut.Lock()
  27. *servingHTTPS = false
  28. mut.Unlock()
  29. }
  30. }