Skip to content

Commit a54ef74

Browse files
author
Erich Shan
committed
Match headers using canonical casing
1 parent 090bfbc commit a54ef74

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

config/crd/bases/http.keda.sh_httpscaledobjects.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ spec:
9797
- name
9898
- value
9999
type: array
100-
uniqueItems: true
101100
replicas:
102101
description: (optional) Replica information
103102
properties:

interceptor/middleware/routing.go

+2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ var _ http.Handler = (*Routing)(nil)
4343
func (rm *Routing) ServeHTTP(w http.ResponseWriter, r *http.Request) {
4444
r = util.RequestWithLoggerWithName(r, "RoutingMiddleware")
4545

46+
// logger := util.LoggerFromContext(r.Context())
4647
httpso := rm.routingTable.Route(r)
48+
4749
if httpso == nil {
4850
if rm.isProbe(r) {
4951
rm.probeHandler.ServeHTTP(w, r)

operator/apis/http/v1alpha1/zz_generated.deepcopy.go

+25-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/routing/tablememory.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package routing
22

33
import (
4+
"net/textproto"
5+
46
"k8s.io/apimachinery/pkg/types"
57

68
httpv1alpha1 "github.com/kedacore/http-add-on/operator/apis/http/v1alpha1"
@@ -103,11 +105,14 @@ func (tm tableMemory) RouteWithHeaders(key Key, httpHeaders map[string][]string)
103105
return httpsoList.Items[0]
104106
}
105107
var httpsoWithoutHeaders *httpv1alpha1.HTTPScaledObject
108+
106109
// route to first httpso which has a matching header
107110
for _, httpso := range httpsoList.Items {
108111
if httpso.Spec.Headers != nil {
109112
for _, header := range httpso.Spec.Headers {
110-
if headerValues, exists := httpHeaders[header.Name]; exists {
113+
// normalize header spacing how golang does it
114+
canonicalHeaderName := textproto.CanonicalMIMEHeaderKey(header.Name)
115+
if headerValues, exists := httpHeaders[canonicalHeaderName]; exists {
111116
for _, v := range headerValues {
112117
if header.Value == v {
113118
return httpso
@@ -124,7 +129,6 @@ func (tm tableMemory) RouteWithHeaders(key Key, httpHeaders map[string][]string)
124129
if httpsoWithoutHeaders != nil {
125130
return httpsoWithoutHeaders
126131
}
127-
128132
// otherwise routing fails
129133
return nil
130134
}

0 commit comments

Comments
 (0)