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.
This commit is contained in:
Dan Walters 2019-03-11 10:49:31 -05:00 committed by Nick Craig-Wood
parent 4827496234
commit 95194adfd5
2 changed files with 9 additions and 3 deletions

View file

@ -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 { func devices() []string {
return []string{ return []string{
"urn:schemas-upnp-org:device:MediaServer:1", "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. // Install handlers to serve SCPD for each UPnP service.
for _, s := range services { for _, s := range services {
p := path.Join("/scpd", s.ServiceId)
s.SCPDURL = p
mux.HandleFunc(s.SCPDURL, func(serviceDesc string) http.HandlerFunc { mux.HandleFunc(s.SCPDURL, func(serviceDesc string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("content-type", `text/xml; charset="utf-8"`) w.Header().Set("content-type", `text/xml; charset="utf-8"`)

View file

@ -59,6 +59,8 @@ func TestRootSCPD(t *testing.T) {
// Make sure that the SCPD contains a CDS service. // Make sure that the SCPD contains a CDS service.
require.Contains(t, string(body), require.Contains(t, string(body),
"<serviceType>urn:schemas-upnp-org:service:ContentDirectory:1</serviceType>") "<serviceType>urn:schemas-upnp-org:service:ContentDirectory:1</serviceType>")
// Ensure that the SCPD url is configured.
require.Regexp(t, "<SCPDURL>/.*</SCPDURL>", string(body))
} }
// Make sure that it serves content from the remote. // Make sure that it serves content from the remote.