diff --git a/conformance/echo-basic/echo-basic.go b/conformance/echo-basic/echo-basic.go index 29a58b5375..ac0e568c02 100644 --- a/conformance/echo-basic/echo-basic.go +++ b/conformance/echo-basic/echo-basic.go @@ -28,6 +28,9 @@ import ( "strconv" "strings" "time" + + "golang.org/x/net/http2" + "golang.org/x/net/http2/h2c" ) // RequestAssertions contains information about the request and the Ingress @@ -76,6 +79,10 @@ func main() { if httpPort == "" { httpPort = "3000" } + h2cPort := os.Getenv("H2C_PORT") + if h2cPort == "" { + h2cPort = "3001" + } httpsPort := os.Getenv("HTTPS_PORT") if httpsPort == "" { @@ -105,6 +112,8 @@ func main() { } }() + go runH2CServer(h2cPort, errchan) + // Enable HTTPS if certificate and private key are given. if os.Getenv("TLS_SERVER_CERT") != "" && os.Getenv("TLS_SERVER_PRIVKEY") != "" { go func() { @@ -152,6 +161,28 @@ func delayResponse(request *http.Request) error { return nil } +func runH2CServer(h2cPort string, errchan chan<- error) { + handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.ProtoMajor != 2 && r.Header.Get("Upgrade") != "h2c" { + w.WriteHeader(http.StatusBadRequest) + fmt.Fprint(w, "Expected h2c request") + return + } + + echoHandler(w, r) + }) + h2c := &http.Server{ + ReadHeaderTimeout: time.Second, + Addr: fmt.Sprintf(":%s", h2cPort), + Handler: h2c.NewHandler(handler, &http2.Server{}), + } + fmt.Printf("Starting server, listening on port %s (h2c)\n", h2cPort) + err := h2c.ListenAndServe() + if err != nil { + errchan <- err + } +} + func echoHandler(w http.ResponseWriter, r *http.Request) { fmt.Printf("Echoing back request made to %s to client (%s)\n", r.RequestURI, r.RemoteAddr) diff --git a/conformance/echo-basic/go.mod b/conformance/echo-basic/go.mod index 9d8d77d80d..148024095d 100644 --- a/conformance/echo-basic/go.mod +++ b/conformance/echo-basic/go.mod @@ -1,3 +1,7 @@ module sigs.k8s.io/gateway-api/conformance/echo-basic go 1.20 + +require golang.org/x/net v0.17.0 + +require golang.org/x/text v0.13.0 // indirect diff --git a/conformance/echo-basic/go.sum b/conformance/echo-basic/go.sum new file mode 100644 index 0000000000..0a8da4eb71 --- /dev/null +++ b/conformance/echo-basic/go.sum @@ -0,0 +1,6 @@ +golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= +golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= diff --git a/go.work.sum b/go.work.sum index e588815616..671b287bf4 100644 --- a/go.work.sum +++ b/go.work.sum @@ -1 +1,18 @@ +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= +golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU= +golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= +golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= +golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=