Commit ae7e0982 authored by Matthew Holt's avatar Matthew Holt

httpserver: Only enable QUIC for sites with TLS & HTTP2 enabled

parent 6e0317a7
...@@ -77,14 +77,14 @@ func NewServer(addr string, group []*SiteConfig) (*Server, error) { ...@@ -77,14 +77,14 @@ func NewServer(addr string, group []*SiteConfig) (*Server, error) {
} }
s.Server.TLSConfig = tlsConfig s.Server.TLSConfig = tlsConfig
// Enable QUIC if desired // if TLS is enabled, make sure we prepare the Server accordingly
if QUIC { if s.Server.TLSConfig != nil {
// enable QUIC if desired (requires HTTP/2)
if HTTP2 && QUIC {
s.quicServer = &h2quic.Server{Server: s.Server} s.quicServer = &h2quic.Server{Server: s.Server}
s.Server.Handler = s.wrapWithSvcHeaders(s.Server.Handler) s.Server.Handler = s.wrapWithSvcHeaders(s.Server.Handler)
} }
// if TLS is enabled, make sure we prepare the Server accordingly
if s.Server.TLSConfig != nil {
// wrap the HTTP handler with a handler that does MITM detection // wrap the HTTP handler with a handler that does MITM detection
tlsh := &tlsHandler{next: s.Server.Handler} tlsh := &tlsHandler{next: s.Server.Handler}
s.Server.Handler = tlsh // this needs to be the "outer" handler when Serve() is called, for type assertion s.Server.Handler = tlsh // this needs to be the "outer" handler when Serve() is called, for type assertion
...@@ -302,7 +302,7 @@ func (s *Server) Serve(ln net.Listener) error { ...@@ -302,7 +302,7 @@ func (s *Server) Serve(ln net.Listener) error {
// ServePacket serves QUIC requests on pc until it is closed. // ServePacket serves QUIC requests on pc until it is closed.
func (s *Server) ServePacket(pc net.PacketConn) error { func (s *Server) ServePacket(pc net.PacketConn) error {
if QUIC { if s.quicServer != nil {
err := s.quicServer.Serve(pc.(*net.UDPConn)) err := s.quicServer.Serve(pc.(*net.UDPConn))
return fmt.Errorf("serving QUIC connections: %v", err) return fmt.Errorf("serving QUIC connections: %v", err)
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment