Allow SSDP search results from inexact searches.

Fixes #24.
This commit is contained in:
John Beisley 2018-03-15 19:11:26 +00:00
parent e25a5cc217
commit 167b9766e5

View File

@ -20,6 +20,11 @@ const (
ssdpSearchPort = 1900
methodSearch = "M-SEARCH"
methodNotify = "NOTIFY"
// SSDPAll is a value for searchTarget that searches for all devices and services.
SSDPAll = "ssdp:all"
// UPNPRootDevice is a value for searchTarget that searches for all root devices.
UPNPRootDevice = "upnp:rootdevice"
)
// SSDPRawSearch performs a fairly raw SSDP search request, and returns the
@ -54,12 +59,15 @@ func SSDPRawSearch(httpu *httpu.HTTPUClient, searchTarget string, maxWaitSeconds
if err != nil {
return nil, err
}
isExactSearch := searchTarget != SSDPAll && searchTarget != UPNPRootDevice
for _, response := range allResponses {
if response.StatusCode != 200 {
log.Printf("ssdp: got response status code %q in search response", response.Status)
continue
}
if st := response.Header.Get("ST"); st != searchTarget {
if st := response.Header.Get("ST"); isExactSearch && st != searchTarget {
continue
}
location, err := response.Location()