From 135b8c0e7575268ee4e16202073f97fae0faf783 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Tue, 3 Sep 2024 17:14:53 +0800 Subject: [PATCH] interop: fix server setup for the HTTP/0.9 server (#4658) --- interop/http09/http_test.go | 4 +--- interop/http09/server.go | 9 ++------- interop/server/main.go | 16 ++++++++-------- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/interop/http09/http_test.go b/interop/http09/http_test.go index fb0e5e06a..c9ef42256 100644 --- a/interop/http09/http_test.go +++ b/interop/http09/http_test.go @@ -27,9 +27,7 @@ var _ = Describe("HTTP 0.9 integration tests", func() { }) BeforeEach(func() { - server := &Server{ - Server: &http.Server{}, - } + server := &Server{} conn, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0}) Expect(err).ToNot(HaveOccurred()) tr := &quic.Transport{Conn: conn} diff --git a/interop/http09/server.go b/interop/http09/server.go index 9a6c7b329..07ac9e11a 100644 --- a/interop/http09/server.go +++ b/interop/http09/server.go @@ -2,7 +2,6 @@ package http09 import ( "context" - "errors" "io" "log" "net/http" @@ -33,15 +32,11 @@ func (w *responseWriter) WriteHeader(int) {} // Server is a HTTP/0.9 server listening for QUIC connections. type Server struct { - *http.Server + Handler *http.ServeMux } -// ListenAndServe listens and serves HTTP/0.9 over QUIC. +// ServeListener serves HTTP/0.9 on all connections accepted from a QUIC listener. func (s *Server) ServeListener(ln *quic.EarlyListener) error { - if s.Server == nil { - return errors.New("use of http3.Server without http.Server") - } - for { conn, err := ln.Accept(context.Background()) if err != nil { diff --git a/interop/server/main.go b/interop/server/main.go index 018d9cf86..a809186d6 100644 --- a/interop/server/main.go +++ b/interop/server/main.go @@ -15,8 +15,6 @@ import ( "github.com/quic-go/quic-go/interop/utils" ) -var tlsConf *tls.Config - func main() { logFile, err := os.Create("/logs/log.txt") if err != nil { @@ -46,20 +44,22 @@ func main() { fmt.Println(err) os.Exit(1) } - tlsConf = &tls.Config{ + tlsConf := &tls.Config{ Certificates: []tls.Certificate{cert}, KeyLogWriter: keyLog, + NextProtos: []string{http09.NextProto}, } switch testcase { case "versionnegotiation", "handshake", "retry", "transfer", "resumption", "multiconnect", "zerortt": - err = runHTTP09Server(quicConf, testcase == "retry") + err = runHTTP09Server(tlsConf, quicConf, testcase == "retry") case "chacha20": reset := qtls.SetCipherSuite(tls.TLS_CHACHA20_POLY1305_SHA256) defer reset() - err = runHTTP09Server(quicConf, false) + err = runHTTP09Server(tlsConf, quicConf, false) case "http3": - err = runHTTP3Server(quicConf) + tlsConf.NextProtos = []string{http3.NextProtoH3} + err = runHTTP3Server(tlsConf, quicConf) default: fmt.Printf("unsupported test case: %s\n", testcase) os.Exit(127) @@ -71,7 +71,7 @@ func main() { } } -func runHTTP09Server(quicConf *quic.Config, forceRetry bool) error { +func runHTTP09Server(tlsConf *tls.Config, quicConf *quic.Config, forceRetry bool) error { http.DefaultServeMux.Handle("/", http.FileServer(http.Dir("/www"))) server := http09.Server{} @@ -94,7 +94,7 @@ func runHTTP09Server(quicConf *quic.Config, forceRetry bool) error { return server.ServeListener(ln) } -func runHTTP3Server(quicConf *quic.Config) error { +func runHTTP3Server(tlsConf *tls.Config, quicConf *quic.Config) error { server := http3.Server{ Addr: ":443", TLSConfig: tlsConf,