mirror of
https://github.com/DeBrosOfficial/network.git
synced 2025-10-06 08:19:07 +00:00
Preserve Hijacker/Flusher/Pusher in statusResponseWriter
Return full topic list without trimming namespace prefix in pubsub handler
This commit is contained in:
parent
c9bb889f8b
commit
44e3f0a795
@ -1,8 +1,11 @@
|
|||||||
package gateway
|
package gateway
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"bufio"
|
||||||
"net/http"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
type statusResponseWriter struct {
|
type statusResponseWriter struct {
|
||||||
@ -22,6 +25,28 @@ func (w *statusResponseWriter) Write(b []byte) (int, error) {
|
|||||||
return n, err
|
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
|
// writeJSON writes JSON with status code
|
||||||
func writeJSON(w http.ResponseWriter, code int, v any) {
|
func writeJSON(w http.ResponseWriter, code int, v any) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
@ -171,14 +171,8 @@ func (g *Gateway) pubsubTopicsHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeError(w, http.StatusInternalServerError, err.Error())
|
writeError(w, http.StatusInternalServerError, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
prefix := ns + "."
|
// Client returns topics already trimmed to its namespace; return as-is
|
||||||
var filtered []string
|
writeJSON(w, http.StatusOK, map[string]any{"topics": all})
|
||||||
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})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolveNamespaceFromRequest gets namespace from context set by auth middleware
|
// resolveNamespaceFromRequest gets namespace from context set by auth middleware
|
||||||
|
Loading…
x
Reference in New Issue
Block a user