chore: update http2 using in test

This commit is contained in:
wwqgtxx 2025-12-17 16:34:32 +08:00
parent b92b38701c
commit e1384e86ab

View File

@ -155,9 +155,9 @@ func NewHttpTestTunnel() *TestTunnel {
io.Copy(io.Discard, r.Body)
render.Data(w, r, httpData[:size])
})
h2Server := &http.Http2Server{}
//h2Server := &http.Http2Server{}
server := http.Server{Handler: r}
_ = http.Http2ConfigureServer(&server, h2Server)
//_ = http.Http2ConfigureServer(&server, h2Server)
go server.Serve(ln)
testFn := func(t *testing.T, proxy C.ProxyAdapter, proto string, size int) {
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s://%s%s?size=%d", proto, remoteAddr, httpPath, size), bytes.NewReader(httpData[:size]))
@ -214,6 +214,9 @@ func NewHttpTestTunnel() *TestTunnel {
defer resp.Body.Close()
assert.Equal(t, http.StatusOK, resp.StatusCode)
if proto == "https" { // ensure server using http2
assert.Equal(t, 2, resp.ProtoMajor)
}
data, err := io.ReadAll(resp.Body)
if !assert.NoError(t, err) {
@ -282,11 +285,12 @@ func NewHttpTestTunnel() *TestTunnel {
if err := tlsConn.HandshakeContext(ctx); err != nil {
return
}
if tlsConn.ConnectionState().NegotiatedProtocol == http.Http2NextProtoTLS {
h2Server.ServeConn(tlsConn, &http.Http2ServeConnOpts{BaseConfig: &server})
} else {
ln.ch <- tlsConn
}
//if tlsConn.ConnectionState().NegotiatedProtocol == http.Http2NextProtoTLS {
// h2Server.ServeConn(tlsConn, &http.Http2ServeConnOpts{BaseConfig: &server})
//} else {
// ln.ch <- tlsConn
//}
ln.ch <- tlsConn
} else {
ln.ch <- c
}