Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #117182: use case-insensitive header keys for http probes #117323

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/openapi-spec/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/openapi-spec/v3/api__v1_openapi.json
Expand Up @@ -2566,7 +2566,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": {
Expand Down
2 changes: 1 addition & 1 deletion api/openapi-spec/v3/apis__apps__v1_openapi.json
Expand Up @@ -2522,7 +2522,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": {
Expand Down
2 changes: 1 addition & 1 deletion api/openapi-spec/v3/apis__batch__v1_openapi.json
Expand Up @@ -1813,7 +1813,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": {
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/core/types.go
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/generated/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/probe/http/request.go
Expand Up @@ -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
}
53 changes: 52 additions & 1 deletion pkg/probe/http/request_test.go
Expand Up @@ -16,7 +16,13 @@ limitations under the License.

package http

import "testing"
import (
"net/http"
"reflect"
"testing"

v1 "k8s.io/api/core/v1"
)

func TestFormatURL(t *testing.T) {
testCases := []struct {
Expand All @@ -38,3 +44,48 @@ func TestFormatURL(t *testing.T) {
}
}
}

func Test_v1HeaderToHTTPHeader(t *testing.T) {
tests := []struct {
name string
headerList []v1.HTTPHeader
want http.Header
}{
{
name: "not empty input",
headerList: []v1.HTTPHeader{
{Name: "Connection", Value: "Keep-Alive"},
{Name: "Content-Type", Value: "text/html"},
{Name: "Accept-Ranges", Value: "bytes"},
},
want: http.Header{
"Connection": {"Keep-Alive"},
"Content-Type": {"text/html"},
"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{},
want: http.Header{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := v1HeaderToHTTPHeader(tt.headerList); !reflect.DeepEqual(got, tt.want) {
t.Errorf("v1HeaderToHTTPHeader() = %v, want %v", got, tt.want)
}
})
}
}
3 changes: 2 additions & 1 deletion staging/src/k8s.io/api/core/v1/generated.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion staging/src/k8s.io/api/core/v1/types.go
Expand Up @@ -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"`
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.