diff --git a/pkg/gateway/http_helpers.go b/pkg/gateway/http_helpers.go index dda9996..388b6bb 100644 --- a/pkg/gateway/http_helpers.go +++ b/pkg/gateway/http_helpers.go @@ -1,8 +1,11 @@ package gateway import ( - "encoding/json" - "net/http" + "bufio" + "encoding/json" + "fmt" + "net" + "net/http" ) type statusResponseWriter struct { @@ -22,6 +25,28 @@ func (w *statusResponseWriter) Write(b []byte) (int, error) { return n, err } +// Ensure websocket upgrades work by preserving Hijacker/Flusher/Pusher +// interfaces when the underlying ResponseWriter supports them. +func (w *statusResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { + if h, ok := w.ResponseWriter.(http.Hijacker); ok { + return h.Hijack() + } + return nil, nil, fmt.Errorf("hijacker not supported") +} + +func (w *statusResponseWriter) Flush() { + if f, ok := w.ResponseWriter.(http.Flusher); ok { + f.Flush() + } +} + +func (w *statusResponseWriter) Push(target string, opts *http.PushOptions) error { + if p, ok := w.ResponseWriter.(http.Pusher); ok { + return p.Push(target, opts) + } + return http.ErrNotSupported +} + // writeJSON writes JSON with status code func writeJSON(w http.ResponseWriter, code int, v any) { w.Header().Set("Content-Type", "application/json") diff --git a/pkg/gateway/pubsub_handlers.go b/pkg/gateway/pubsub_handlers.go index 3bf4b23..2eb3682 100644 --- a/pkg/gateway/pubsub_handlers.go +++ b/pkg/gateway/pubsub_handlers.go @@ -171,14 +171,8 @@ func (g *Gateway) pubsubTopicsHandler(w http.ResponseWriter, r *http.Request) { writeError(w, http.StatusInternalServerError, err.Error()) return } - prefix := ns + "." - var filtered []string - for _, t := range all { - if len(t) >= len(prefix) && t[:len(prefix)] == prefix { - filtered = append(filtered, t[len(prefix):]) - } - } - writeJSON(w, http.StatusOK, map[string]any{"topics": filtered}) + // Client returns topics already trimmed to its namespace; return as-is + writeJSON(w, http.StatusOK, map[string]any{"topics": all}) } // resolveNamespaceFromRequest gets namespace from context set by auth middleware