mirror of
https://github.com/DeBrosOfficial/network.git
synced 2025-10-06 06:19:08 +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
|
||||
|
||||
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")
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user