mirror of
https://github.com/gesellix/Bose-SoundTouch.git
synced 2026-08-19 09:06:14 +00:00
refactor(handlers): rename proxy-era leftovers to match public names
After the proxy/mirror removal, two internal Server fields kept their
historical "proxy" prefix even though no proxy code exists anymore:
- s.proxyRedact still controls recorder.Redact for sensitive-header
scrubbing (server.go:393)
- s.proxyLogBody still controls the [UNHANDLED] body preview in the
catch-all (handlers_catchall.go:14)
Both names misled — they read as proxy-related. Renamed to match the
public-facing names that have been used all along: the CLI flags are
--redact-logs / --log-bodies, the persisted Settings fields are
RedactLogs / LogBodies, and the JSON keys are redact_logs / log_bodies.
proxyRedact → redactLogs
proxyLogBody → logBodies
Also renamed the file that now contains only HandleNotFound:
pkg/service/handlers/handlers_proxy.go → handlers_catchall.go
pkg/service/handlers/handlers_proxy_test.go → handlers_catchall_test.go
git mv preserves history. NewServer's positional parameter list is
unchanged at the call site (cmd/soundtouch-service/main.go:391).
go build ./... clean. go test ./... clean except the pre-existing
TestDocsConsistency (unrelated). golangci-lint run ./... 0 issues.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
018e9fd7cb
commit
1da654c9b9
@@ -9,9 +9,9 @@ import (
|
||||
|
||||
// HandleNotFound handles requests that don't match any route.
|
||||
// It always logs [UNHANDLED] so unimplemented endpoints are visible in plain output.
|
||||
// When proxyLogBody is enabled it also logs the request body (truncated to 512 bytes).
|
||||
// When logBodies is enabled it also logs the request body (truncated to 512 bytes).
|
||||
func (s *Server) HandleNotFound(w http.ResponseWriter, r *http.Request) {
|
||||
if s.proxyLogBody && r.Body != nil {
|
||||
if s.logBodies && r.Body != nil {
|
||||
body, _ := io.ReadAll(r.Body)
|
||||
r.Body = io.NopCloser(bytes.NewBuffer(body))
|
||||
|
||||
+4
-4
@@ -39,7 +39,7 @@ func TestHandleNotFound_UnhandledLogging(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("includes body in log when proxyLogBody is true", func(t *testing.T) {
|
||||
t.Run("includes body in log when logBodies is true", func(t *testing.T) {
|
||||
ds := datastore.NewDataStore(t.TempDir())
|
||||
server := NewServer(ds, nil, "http://localhost", false, true, false)
|
||||
|
||||
@@ -50,11 +50,11 @@ func TestHandleNotFound_UnhandledLogging(t *testing.T) {
|
||||
})
|
||||
|
||||
if !strings.Contains(logged, "<payload/>") {
|
||||
t.Errorf("expected body in log when proxyLogBody=true, got: %s", logged)
|
||||
t.Errorf("expected body in log when logBodies=true, got: %s", logged)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("omits body from log when proxyLogBody is false", func(t *testing.T) {
|
||||
t.Run("omits body from log when logBodies is false", func(t *testing.T) {
|
||||
ds := datastore.NewDataStore(t.TempDir())
|
||||
server := NewServer(ds, nil, "http://localhost", false, false, false)
|
||||
|
||||
@@ -65,7 +65,7 @@ func TestHandleNotFound_UnhandledLogging(t *testing.T) {
|
||||
})
|
||||
|
||||
if strings.Contains(logged, "<secret/>") {
|
||||
t.Errorf("expected body omitted when proxyLogBody=false, got: %s", logged)
|
||||
t.Errorf("expected body omitted when logBodies=false, got: %s", logged)
|
||||
}
|
||||
if !strings.Contains(logged, "[UNHANDLED]") {
|
||||
t.Errorf("expected [UNHANDLED] even without body, got: %s", logged)
|
||||
@@ -154,7 +154,7 @@ func (s *Server) HandleGetSettings(w http.ResponseWriter, _ *http.Request) {
|
||||
dnsUpstream := s.dnsUpstream
|
||||
dnsBindAddr := s.dnsBindAddr
|
||||
internalPaths := s.internalPaths
|
||||
redact, logBody, record := s.proxyRedact, s.proxyLogBody, s.recordEnabled
|
||||
redact, logBody, record := s.redactLogs, s.logBodies, s.recordEnabled
|
||||
shortcuts := s.shortcuts
|
||||
spotifyConfigured := s.spotifyService != nil
|
||||
spotifyClientID := s.spotifyClientID
|
||||
@@ -317,8 +317,8 @@ func (s *Server) HandleUpdateSettings(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Persist to datastore
|
||||
// Access fields directly since we already hold the lock
|
||||
currentRedact := s.proxyRedact
|
||||
currentLogBody := s.proxyLogBody
|
||||
currentRedact := s.redactLogs
|
||||
currentLogBody := s.logBodies
|
||||
currentRecord := s.recordEnabled
|
||||
currentHTTPS := s.httpsServerURL
|
||||
|
||||
@@ -880,8 +880,8 @@ func (s *Server) HandleUpdateProxySettings(w http.ResponseWriter, r *http.Reques
|
||||
}
|
||||
|
||||
s.mu.Lock()
|
||||
s.proxyRedact = settings.Redact
|
||||
s.proxyLogBody = settings.LogBody
|
||||
s.redactLogs = settings.Redact
|
||||
s.logBodies = settings.LogBody
|
||||
s.recordEnabled = settings.Record
|
||||
|
||||
if s.recorder != nil {
|
||||
@@ -898,8 +898,8 @@ func (s *Server) HandleUpdateProxySettings(w http.ResponseWriter, r *http.Reques
|
||||
err := s.ds.SaveSettings(datastore.Settings{
|
||||
ServerURL: serverURL,
|
||||
HTTPServerURL: httpsServerURL,
|
||||
RedactLogs: s.proxyRedact,
|
||||
LogBodies: s.proxyLogBody,
|
||||
RedactLogs: s.redactLogs,
|
||||
LogBodies: s.logBodies,
|
||||
RecordInteractions: s.recordEnabled,
|
||||
DiscoveryInterval: discoveryInterval,
|
||||
DiscoveryEnabled: discoveryEnabled,
|
||||
|
||||
@@ -33,8 +33,8 @@ func TestProxySettingsAPI(t *testing.T) {
|
||||
defer ts.Close()
|
||||
|
||||
// Initial State
|
||||
server.proxyRedact = true
|
||||
server.proxyLogBody = false
|
||||
server.redactLogs = true
|
||||
server.logBodies = false
|
||||
|
||||
// 1. Test GET
|
||||
res, err := http.Get(ts.URL + "/setup/proxy-settings")
|
||||
@@ -80,8 +80,8 @@ func TestProxySettingsAPI(t *testing.T) {
|
||||
}
|
||||
|
||||
// Verify server state
|
||||
if server.proxyRedact != false || server.proxyLogBody != true {
|
||||
t.Errorf("POST: Server state did not update: redact=%v, logBody=%v", server.proxyRedact, server.proxyLogBody)
|
||||
if server.redactLogs != false || server.logBodies != true {
|
||||
t.Errorf("POST: Server state did not update: redact=%v, logBody=%v", server.redactLogs, server.logBodies)
|
||||
}
|
||||
|
||||
res, err = http.Get(ts.URL + "/setup/proxy-settings")
|
||||
|
||||
@@ -35,8 +35,8 @@ type Server struct {
|
||||
serverURL string
|
||||
httpsServerURL string
|
||||
discovering bool
|
||||
proxyRedact bool
|
||||
proxyLogBody bool
|
||||
redactLogs bool
|
||||
logBodies bool
|
||||
recordEnabled bool
|
||||
discoveryInterval time.Duration
|
||||
discoveryEnabled bool
|
||||
@@ -86,13 +86,13 @@ var bufferPool = sync.Pool{
|
||||
}
|
||||
|
||||
// NewServer creates a new SoundTouch service server.
|
||||
func NewServer(ds *datastore.DataStore, sm *setup.Manager, serverURL string, proxyRedact, proxyLogBody, recordEnabled bool) *Server {
|
||||
func NewServer(ds *datastore.DataStore, sm *setup.Manager, serverURL string, redactLogs, logBodies, recordEnabled bool) *Server {
|
||||
s := &Server{
|
||||
ds: ds,
|
||||
sm: sm,
|
||||
serverURL: serverURL,
|
||||
proxyRedact: proxyRedact,
|
||||
proxyLogBody: proxyLogBody,
|
||||
redactLogs: redactLogs,
|
||||
logBodies: logBodies,
|
||||
recordEnabled: recordEnabled,
|
||||
discoveryInterval: 5 * time.Minute,
|
||||
discoveryEnabled: true,
|
||||
@@ -390,7 +390,7 @@ func (s *Server) SetRecorder(r *proxy.Recorder) {
|
||||
|
||||
s.recorder = r
|
||||
if r != nil {
|
||||
r.Redact = s.proxyRedact
|
||||
r.Redact = s.redactLogs
|
||||
}
|
||||
}
|
||||
|
||||
@@ -568,7 +568,7 @@ func (s *Server) GetProxySettings() (bool, bool, bool) {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
|
||||
return s.proxyRedact, s.proxyLogBody, s.recordEnabled
|
||||
return s.redactLogs, s.logBodies, s.recordEnabled
|
||||
}
|
||||
|
||||
// DiscoverDevices starts a background device discovery process.
|
||||
|
||||
Reference in New Issue
Block a user