interop: fix server setup for the HTTP/0.9 server (#4658)

This commit is contained in:
Marten Seemann
2024-09-03 17:14:53 +08:00
committed by GitHub
parent 26a3525337
commit 135b8c0e75
3 changed files with 11 additions and 18 deletions

View File

@@ -27,9 +27,7 @@ var _ = Describe("HTTP 0.9 integration tests", func() {
}) })
BeforeEach(func() { BeforeEach(func() {
server := &Server{ server := &Server{}
Server: &http.Server{},
}
conn, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0}) conn, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 0})
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
tr := &quic.Transport{Conn: conn} tr := &quic.Transport{Conn: conn}

View File

@@ -2,7 +2,6 @@ package http09
import ( import (
"context" "context"
"errors"
"io" "io"
"log" "log"
"net/http" "net/http"
@@ -33,15 +32,11 @@ func (w *responseWriter) WriteHeader(int) {}
// Server is a HTTP/0.9 server listening for QUIC connections. // Server is a HTTP/0.9 server listening for QUIC connections.
type Server struct { 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 { func (s *Server) ServeListener(ln *quic.EarlyListener) error {
if s.Server == nil {
return errors.New("use of http3.Server without http.Server")
}
for { for {
conn, err := ln.Accept(context.Background()) conn, err := ln.Accept(context.Background())
if err != nil { if err != nil {

View File

@@ -15,8 +15,6 @@ import (
"github.com/quic-go/quic-go/interop/utils" "github.com/quic-go/quic-go/interop/utils"
) )
var tlsConf *tls.Config
func main() { func main() {
logFile, err := os.Create("/logs/log.txt") logFile, err := os.Create("/logs/log.txt")
if err != nil { if err != nil {
@@ -46,20 +44,22 @@ func main() {
fmt.Println(err) fmt.Println(err)
os.Exit(1) os.Exit(1)
} }
tlsConf = &tls.Config{ tlsConf := &tls.Config{
Certificates: []tls.Certificate{cert}, Certificates: []tls.Certificate{cert},
KeyLogWriter: keyLog, KeyLogWriter: keyLog,
NextProtos: []string{http09.NextProto},
} }
switch testcase { switch testcase {
case "versionnegotiation", "handshake", "retry", "transfer", "resumption", "multiconnect", "zerortt": case "versionnegotiation", "handshake", "retry", "transfer", "resumption", "multiconnect", "zerortt":
err = runHTTP09Server(quicConf, testcase == "retry") err = runHTTP09Server(tlsConf, quicConf, testcase == "retry")
case "chacha20": case "chacha20":
reset := qtls.SetCipherSuite(tls.TLS_CHACHA20_POLY1305_SHA256) reset := qtls.SetCipherSuite(tls.TLS_CHACHA20_POLY1305_SHA256)
defer reset() defer reset()
err = runHTTP09Server(quicConf, false) err = runHTTP09Server(tlsConf, quicConf, false)
case "http3": case "http3":
err = runHTTP3Server(quicConf) tlsConf.NextProtos = []string{http3.NextProtoH3}
err = runHTTP3Server(tlsConf, quicConf)
default: default:
fmt.Printf("unsupported test case: %s\n", testcase) fmt.Printf("unsupported test case: %s\n", testcase)
os.Exit(127) 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"))) http.DefaultServeMux.Handle("/", http.FileServer(http.Dir("/www")))
server := http09.Server{} server := http09.Server{}
@@ -94,7 +94,7 @@ func runHTTP09Server(quicConf *quic.Config, forceRetry bool) error {
return server.ServeListener(ln) return server.ServeListener(ln)
} }
func runHTTP3Server(quicConf *quic.Config) error { func runHTTP3Server(tlsConf *tls.Config, quicConf *quic.Config) error {
server := http3.Server{ server := http3.Server{
Addr: ":443", Addr: ":443",
TLSConfig: tlsConf, TLSConfig: tlsConf,