From 10a8ec5b2cc251d0021d8ca553cce649ee38c7ba Mon Sep 17 00:00:00 2001 From: dddddai Date: Wed, 12 Apr 2023 15:39:55 +0800 Subject: [PATCH] use case-insensitive header keys for http probes --- api/openapi-spec/swagger.json | 2 +- api/openapi-spec/v3/api__v1_openapi.json | 2 +- api/openapi-spec/v3/apis__apps__v1_openapi.json | 2 +- api/openapi-spec/v3/apis__batch__v1_openapi.json | 2 +- pkg/apis/core/types.go | 3 ++- pkg/generated/openapi/zz_generated.openapi.go | 2 +- pkg/probe/http/request.go | 2 +- pkg/probe/http/request_test.go | 11 +++++++++++ staging/src/k8s.io/api/core/v1/generated.proto | 3 ++- staging/src/k8s.io/api/core/v1/types.go | 3 ++- .../k8s.io/api/core/v1/types_swagger_doc_generated.go | 2 +- 11 files changed, 24 insertions(+), 10 deletions(-) diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index 12903fd69f2..651571df6fc 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -6192,7 +6192,7 @@ "description": "HTTPHeader describes a custom header to be used in HTTP probes", "properties": { "name": { - "description": "The header field name", + "description": "The header field name. This will be canonicalized upon output, so case-variant names will be understood as the same header.", "type": "string" }, "value": { diff --git a/api/openapi-spec/v3/api__v1_openapi.json b/api/openapi-spec/v3/api__v1_openapi.json index 9684216b70f..c734945991b 100644 --- a/api/openapi-spec/v3/api__v1_openapi.json +++ b/api/openapi-spec/v3/api__v1_openapi.json @@ -2632,7 +2632,7 @@ "properties": { "name": { "default": "", - "description": "The header field name", + "description": "The header field name. This will be canonicalized upon output, so case-variant names will be understood as the same header.", "type": "string" }, "value": { diff --git a/api/openapi-spec/v3/apis__apps__v1_openapi.json b/api/openapi-spec/v3/apis__apps__v1_openapi.json index 395e98c8099..7f1f1a2cffc 100644 --- a/api/openapi-spec/v3/apis__apps__v1_openapi.json +++ b/api/openapi-spec/v3/apis__apps__v1_openapi.json @@ -2568,7 +2568,7 @@ "properties": { "name": { "default": "", - "description": "The header field name", + "description": "The header field name. This will be canonicalized upon output, so case-variant names will be understood as the same header.", "type": "string" }, "value": { diff --git a/api/openapi-spec/v3/apis__batch__v1_openapi.json b/api/openapi-spec/v3/apis__batch__v1_openapi.json index 43261ee01c2..cb419018383 100644 --- a/api/openapi-spec/v3/apis__batch__v1_openapi.json +++ b/api/openapi-spec/v3/apis__batch__v1_openapi.json @@ -1859,7 +1859,7 @@ "properties": { "name": { "default": "", - "description": "The header field name", + "description": "The header field name. This will be canonicalized upon output, so case-variant names will be understood as the same header.", "type": "string" }, "value": { diff --git a/pkg/apis/core/types.go b/pkg/apis/core/types.go index d8f657b7423..5d5b51b1bce 100644 --- a/pkg/apis/core/types.go +++ b/pkg/apis/core/types.go @@ -2037,7 +2037,8 @@ type SecretEnvSource struct { // HTTPHeader describes a custom header to be used in HTTP probes type HTTPHeader struct { - // The header field name + // The header field name. + // This will be canonicalized upon output, so case-variant names will be understood as the same header. Name string // The header field value Value string diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index 9a7dd5d6720..191735df92c 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -19979,7 +19979,7 @@ func schema_k8sio_api_core_v1_HTTPHeader(ref common.ReferenceCallback) common.Op Properties: map[string]spec.Schema{ "name": { SchemaProps: spec.SchemaProps{ - Description: "The header field name", + Description: "The header field name. This will be canonicalized upon output, so case-variant names will be understood as the same header.", Default: "", Type: []string{"string"}, Format: "", diff --git a/pkg/probe/http/request.go b/pkg/probe/http/request.go index 4285c0a4ccb..fb7f818b249 100644 --- a/pkg/probe/http/request.go +++ b/pkg/probe/http/request.go @@ -113,7 +113,7 @@ func formatURL(scheme string, host string, port int, path string) *url.URL { func v1HeaderToHTTPHeader(headerList []v1.HTTPHeader) http.Header { headers := make(http.Header) for _, header := range headerList { - headers[header.Name] = append(headers[header.Name], header.Value) + headers.Add(header.Name, header.Value) } return headers } diff --git a/pkg/probe/http/request_test.go b/pkg/probe/http/request_test.go index 77c3d919596..6bc243a3dbe 100644 --- a/pkg/probe/http/request_test.go +++ b/pkg/probe/http/request_test.go @@ -64,6 +64,17 @@ func Test_v1HeaderToHTTPHeader(t *testing.T) { "Accept-Ranges": {"bytes"}, }, }, + { + name: "case insensitive", + headerList: []v1.HTTPHeader{ + {Name: "HOST", Value: "example.com"}, + {Name: "FOO-bAR", Value: "value"}, + }, + want: http.Header{ + "Host": {"example.com"}, + "Foo-Bar": {"value"}, + }, + }, { name: "empty input", headerList: []v1.HTTPHeader{}, diff --git a/staging/src/k8s.io/api/core/v1/generated.proto b/staging/src/k8s.io/api/core/v1/generated.proto index 94e0a71156c..8ef67ca40bd 100644 --- a/staging/src/k8s.io/api/core/v1/generated.proto +++ b/staging/src/k8s.io/api/core/v1/generated.proto @@ -1853,7 +1853,8 @@ message HTTPGetAction { // HTTPHeader describes a custom header to be used in HTTP probes message HTTPHeader { - // The header field name + // The header field name. + // This will be canonicalized upon output, so case-variant names will be understood as the same header. optional string name = 1; // The header field value diff --git a/staging/src/k8s.io/api/core/v1/types.go b/staging/src/k8s.io/api/core/v1/types.go index c9bb18a2cc7..c831d5961cf 100644 --- a/staging/src/k8s.io/api/core/v1/types.go +++ b/staging/src/k8s.io/api/core/v1/types.go @@ -2137,7 +2137,8 @@ type SecretEnvSource struct { // HTTPHeader describes a custom header to be used in HTTP probes type HTTPHeader struct { - // The header field name + // The header field name. + // This will be canonicalized upon output, so case-variant names will be understood as the same header. Name string `json:"name" protobuf:"bytes,1,opt,name=name"` // The header field value Value string `json:"value" protobuf:"bytes,2,opt,name=value"` diff --git a/staging/src/k8s.io/api/core/v1/types_swagger_doc_generated.go b/staging/src/k8s.io/api/core/v1/types_swagger_doc_generated.go index a2cf00db87a..a01ae371737 100644 --- a/staging/src/k8s.io/api/core/v1/types_swagger_doc_generated.go +++ b/staging/src/k8s.io/api/core/v1/types_swagger_doc_generated.go @@ -832,7 +832,7 @@ func (HTTPGetAction) SwaggerDoc() map[string]string { var map_HTTPHeader = map[string]string{ "": "HTTPHeader describes a custom header to be used in HTTP probes", - "name": "The header field name", + "name": "The header field name. This will be canonicalized upon output, so case-variant names will be understood as the same header.", "value": "The header field value", }