Skip to content

Commit 8eba7b6

Browse files
authored
limit HTTPRouteHTTPSListenerDetectMisdirectedRequests to h2 only (#4665) (#4667)
* limit HTTPRouteHTTPSListenerDetectMisdirectedRequests to h2 only * fix lint --------- Signed-off-by: zirain <zirain2009@gmail.com>
1 parent a43b54f commit 8eba7b6

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

conformance/tests/httproute-https-listener-detect-misdirected-requests.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"sigs.k8s.io/gateway-api/conformance/utils/http"
2525
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
26+
"sigs.k8s.io/gateway-api/conformance/utils/roundtripper"
2627
"sigs.k8s.io/gateway-api/conformance/utils/suite"
2728
"sigs.k8s.io/gateway-api/conformance/utils/tls"
2829
"sigs.k8s.io/gateway-api/pkg/features"
@@ -92,7 +93,11 @@ var HTTPRouteHTTPSListenerDetectMisdirectedRequests = suite.ConformanceTest{
9293

9394
for i, tc := range cases {
9495
expected := http.ExpectedResponse{
95-
Request: http.Request{Host: tc.host, Path: "/detect-misdirected-requests"},
96+
Request: http.Request{
97+
Host: tc.host,
98+
Path: "/detect-misdirected-requests",
99+
Protocol: roundtripper.H2Protocol,
100+
},
96101
Response: http.Response{StatusCodes: []int{tc.statusCode}},
97102
Backend: tc.backend,
98103
Namespace: "gateway-conformance-infra",

conformance/utils/roundtripper/roundtripper.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
const (
4242
H2CPriorKnowledgeProtocol = "H2C_PRIOR_KNOWLEDGE"
4343
HTTPSProtocol = "HTTPS"
44+
H2Protocol = "H2"
4445
)
4546

4647
// RoundTripper is an interface used to make requests within conformance tests.
@@ -151,6 +152,18 @@ func (d *DefaultRoundTripper) httpTransport(request Request) (http.RoundTripper,
151152
return transport, nil
152153
}
153154

155+
func (d *DefaultRoundTripper) h2Transport(request Request) (http.RoundTripper, error) {
156+
transport := &http2.Transport{}
157+
158+
tlsConfig, err := createTLSClientConfig(request)
159+
if err != nil {
160+
return nil, err
161+
}
162+
transport.TLSClientConfig = tlsConfig
163+
164+
return transport, nil
165+
}
166+
154167
func (d *DefaultRoundTripper) h2cPriorKnowledgeTransport(request Request) (http.RoundTripper, error) {
155168
if request.ServerName != "" && len(request.ServerCertificate) > 0 {
156169
return nil, errors.New("request has configured trusted CA certificates but h2 prior knowledge is not encrypted")
@@ -178,6 +191,8 @@ func (d *DefaultRoundTripper) CaptureRoundTrip(request Request) (*CapturedReques
178191
switch request.Protocol {
179192
case H2CPriorKnowledgeProtocol:
180193
transport, err = d.h2cPriorKnowledgeTransport(request)
194+
case H2Protocol:
195+
transport, err = d.h2Transport(request)
181196
default:
182197
transport, err = d.httpTransport(request)
183198
}

0 commit comments

Comments
 (0)