Skip to content

Commit

Permalink
Fixes #2046 Remove istio headers in outbound activator requests
Browse files Browse the repository at this point in the history
  • Loading branch information
dprotaso committed Sep 18, 2018
1 parent 699d343 commit 55d5545
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/activator/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,28 @@ func (a *ActivationHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
proxy := httputil.NewSingleHostReverseProxy(target)
proxy.Transport = a.Transport

setupPruningHeaders(proxy)

proxy.ServeHTTP(w, r)
}

func setupPruningHeaders(p *httputil.ReverseProxy) {
headersToRemove := []string{
activator.ConfigurationHeader,
activator.RevisionHeaderName,
activator.RevisionHeaderNamespace,
}

orig := p.Director
p.Director = func(r *http.Request) {
if orig != nil {
orig(r)
}

for _, h := range headersToRemove {
if r.Header.Get(h) != "" {
r.Header.Del(h)
}
}
}
}
17 changes: 17 additions & 0 deletions pkg/activator/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func TestActivationHandler(t *testing.T) {
label string
namespace string
name string
config string
wantBody string
wantCode int
wantErr error
Expand All @@ -83,6 +84,7 @@ func TestActivationHandler(t *testing.T) {
label: "active endpoint",
namespace: "real-namespace",
name: "real-name",
config: "configuration-name",
wantBody: "everything good!",
wantCode: http.StatusOK,
wantErr: nil,
Expand All @@ -91,6 +93,7 @@ func TestActivationHandler(t *testing.T) {
label: "no active endpoint",
namespace: "fake-namespace",
name: "fake-name",
config: "configuration-name",
wantBody: errMsg("not found!"),
wantCode: http.StatusNotFound,
wantErr: nil,
Expand All @@ -99,6 +102,7 @@ func TestActivationHandler(t *testing.T) {
label: "request error",
namespace: "real-namespace",
name: "real-name",
config: "configuration-name",
wantBody: "",
wantCode: http.StatusBadGateway,
wantErr: errors.New("request error!"),
Expand All @@ -112,6 +116,18 @@ func TestActivationHandler(t *testing.T) {
return nil, e.wantErr
}

if r.Header.Get(activator.RevisionHeaderName) != "" {
t.Error("Activator revision name header sent in outbound request")
}

if r.Header.Get(activator.RevisionHeaderNamespace) != "" {
t.Error("Activator revision namespace header sent in outbound request")
}

if r.Header.Get(activator.ConfigurationHeader) != "" {
t.Error("Activator configuration name header sent in outbound request")
}

return http.DefaultTransport.RoundTrip(r)
})

Expand All @@ -126,6 +142,7 @@ func TestActivationHandler(t *testing.T) {
req := httptest.NewRequest("POST", "http://example.com", nil)
req.Header.Set(activator.RevisionHeaderNamespace, e.namespace)
req.Header.Set(activator.RevisionHeaderName, e.name)
req.Header.Set(activator.ConfigurationHeader, e.config)

handler.ServeHTTP(resp, req)

Expand Down

0 comments on commit 55d5545

Please sign in to comment.