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

Read header added by Queue-proxy in Activator #15606

Open
bonavadeur opened this issue Nov 8, 2024 · 2 comments
Open

Read header added by Queue-proxy in Activator #15606

bonavadeur opened this issue Nov 8, 2024 · 2 comments
Labels
kind/question Further information is requested lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.

Comments

@bonavadeur
Copy link

Hi all, I am working with Knative Serving. I modified the Queue-Proxy successfully to add some extra headers into HTTP packet response from Application Pod back to Activator. The extra-headers I added into HTTP response from queue-proxy can be captured in Wireshark. Now, how can I read this header in Activator side? Where is the codes in Activator that receive HTTP response from queue-proxy back to Activator?

Thanks for helps ❤️

@bonavadeur bonavadeur added the kind/question Further information is requested label Nov 8, 2024
@skonto
Copy link
Contributor

skonto commented Nov 26, 2024

Hi @bonavadeur, we proxy the request here. You could use something like the following:

diff --git a/pkg/activator/handler/handler.go b/pkg/activator/handler/handler.go
index 74acbb7ed..6a9fea58d 100644
--- a/pkg/activator/handler/handler.go
+++ b/pkg/activator/handler/handler.go
@@ -19,6 +19,7 @@ package handler
 import (
 	"context"
 	"errors"
+	"fmt"
 	"net/http"
 	"net/http/httputil"
 	"strconv"
@@ -140,10 +141,18 @@ func (a *activationHandler) proxyRequest(revID types.NamespacedName, w http.Resp
 	proxy.ErrorHandler = func(w http.ResponseWriter, req *http.Request, err error) {
 		pkghandler.Error(a.logger.With(zap.String(logkey.Key, revID.String())))(w, req, err)
 	}
+	proxy.ModifyResponse = UpdateResponse
 
 	proxy.ServeHTTP(w, r)
 }
 
+func UpdateResponse(r *http.Response) error {
+	for k, v := range r.Header {
+		fmt.Println(k, "value is", v)
+	}
+	return nil
+}
+
 // useSecurePort replaces the default port with HTTPS port (8112).
 // TODO: endpointsToDests() should support HTTPS instead of this overwrite but it needs metadata request to be encrypted.
 // This code should be removed when https://github.com/knative/serving/issues/12821 was solved.

This prints:

Content-Length value is [20]
Content-Type value is [text/plain; charset=utf-8]
Date value is [Tue, 26 Nov 2024 11:18:57 GMT]

Copy link

This issue is stale because it has been open for 90 days with no
activity. It will automatically close after 30 more days of
inactivity. Reopen the issue with /reopen. Mark the issue as
fresh by adding the comment /remove-lifecycle stale.

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/question Further information is requested lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.
Projects
None yet
Development

No branches or pull requests

2 participants