From 95194adfd5134903e86eb63fcd11490144b502f9 Mon Sep 17 00:00:00 2001 From: Dan Walters Date: Mon, 11 Mar 2019 10:49:31 -0500 Subject: [PATCH] dlna: fix root XML service descriptor The SCPD URL was being set after marshalling the XML, and thus coming out blank. Now works on my Samsung TV, and likely fixes some issues reported by others in #2648. --- cmd/serve/dlna/dlna.go | 10 +++++++--- cmd/serve/dlna/dlna_test.go | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cmd/serve/dlna/dlna.go b/cmd/serve/dlna/dlna.go index 960e7db32..b430634a4 100644 --- a/cmd/serve/dlna/dlna.go +++ b/cmd/serve/dlna/dlna.go @@ -86,6 +86,13 @@ var services = []*service{ }, } +func init() { + for _, s := range services { + p := path.Join("/scpd", s.ServiceId) + s.SCPDURL = p + } +} + func devices() []string { return []string{ "urn:schemas-upnp-org:device:MediaServer:1", @@ -250,9 +257,6 @@ func (s *server) initMux(mux *http.ServeMux) { // Install handlers to serve SCPD for each UPnP service. for _, s := range services { - p := path.Join("/scpd", s.ServiceId) - s.SCPDURL = p - mux.HandleFunc(s.SCPDURL, func(serviceDesc string) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("content-type", `text/xml; charset="utf-8"`) diff --git a/cmd/serve/dlna/dlna_test.go b/cmd/serve/dlna/dlna_test.go index 0f5c59188..a2ef03445 100644 --- a/cmd/serve/dlna/dlna_test.go +++ b/cmd/serve/dlna/dlna_test.go @@ -59,6 +59,8 @@ func TestRootSCPD(t *testing.T) { // Make sure that the SCPD contains a CDS service. require.Contains(t, string(body), "urn:schemas-upnp-org:service:ContentDirectory:1") + // Ensure that the SCPD url is configured. + require.Regexp(t, "/.*", string(body)) } // Make sure that it serves content from the remote.