Repository: knative/serving
Pull request #7814 (2020-05-01 21:32:09)

Use new go1.14 lib func for header values
In celebration of labor day outside of US,  we're reducing our code base and improving tests.
/assign @tcnghia mattmoor

knative-prow-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative/serving/pull/7814#" title="Author self-approved">vagababov</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=knative%2Fserving).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[pkg/http/OWNERS](https://github.com/knative/serving/blob/master/pkg/http/OWNERS)~~ [vagababov]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
tcnghia: /lgtm
/approve
knative-prow-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative/serving/pull/7814#issuecomment-622579781" title="Approved">tcnghia</a>*, *<a href="https://github.com/knative/serving/pull/7814#" title="Author self-approved">vagababov</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=knative%2Fserving).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[pkg/http/OWNERS](https://github.com/knative/serving/blob/master/pkg/http/OWNERS)~~ [tcnghia,vagababov]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/pkg/http/header.go b/pkg/http/header.go
index 779b2491b..7e3cbe54b 100644
--- a/pkg/http/header.go
+++ b/pkg/http/header.go
@@ -19,19 +19,12 @@ package http
 import "net/http"
 
 // LastHeaderValue gets the last value associated with the given key.
-// It is case insensitive; textproto.CanonicalMIMEHeaderKey is used
-// to canonicalize the provided key.
+// Key is canonicalized.
 // If there are no values associated with the key, Get returns "".
 func LastHeaderValue(header http.Header, key string) string {
-	if header == nil {
-		return ""
+	v := header.Values(key)
+	if l := len(v); l > 0 {
+		return v[l-1]
 	}
-
-	v := header[http.CanonicalHeaderKey(key)]
-
-	if len(v) == 0 {
-		return ""
-	}
-
-	return v[len(v)-1]
+	return ""
 }


Test patch:
diff --git a/pkg/http/header_test.go b/pkg/http/header_test.go
index 1d3f8b15b..c957e6b4a 100644
--- a/pkg/http/header_test.go
+++ b/pkg/http/header_test.go
@@ -22,7 +22,10 @@ import (
 )
 
 func TestLastHeaderValue(t *testing.T) {
-	headerKey := "Header-Key"
+	const (
+		headerKey    = "Header-Key"
+		nonCanonical = "hEaDer-kEY"
+	)
 
 	tests := []struct {
 		name     string
@@ -53,9 +56,9 @@ func TestLastHeaderValue(t *testing.T) {
 	}}
 
 	for _, test := range tests {
-		got := LastHeaderValue(test.headers, headerKey)
+		got := LastHeaderValue(test.headers, nonCanonical)
 		if got != test.expected {
-			t.Errorf("Unexpected header value got - %q want - %q", got, test.expected)
+			t.Errorf("Got = %q, want: %q", got, test.expected)
 		}
 	}
 }
diff --git a/test/conformance/ingress/util.go b/test/conformance/ingress/util.go
index 97e5c47c9..4990cae6a 100644
--- a/test/conformance/ingress/util.go
+++ b/test/conformance/ingress/util.go
@@ -62,7 +62,8 @@ var dialBackoff = wait.Backoff{
 	Duration: 50 * time.Millisecond,
 	Factor:   1.4,
 	Jitter:   0.1, // At most 10% jitter.
-	Steps:    18,
+	Steps:    100,
+	Cap:      10 * time.Second,
 }
 
 // uaRoundTripper wraps the given http.RoundTripper and