Skip to content

Commit

Permalink
Respond with proper ST header on SSDP upnp requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatson committed Aug 27, 2024
1 parent c14ccd5 commit ef99380
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions crates/upnp-serve/src/ssdp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,18 @@ USN: {usn}::{kind}\r
)
}

fn generate_ssdp_discover_response(&self) -> String {
fn generate_ssdp_discover_response(&self, st: &str) -> String {
let location = &self.opts.description_http_location;
let usn = &self.opts.usn;
let media_server = UPNP_KIND_MEDIASERVER;
let server = &self.opts.server_string;
format!(
"HTTP/1.1 200 OK\r
Cache-Control: max-age=75\r
Ext: \r
Location: {location}\r
Server: {server}\r
St: {media_server}\r
Usn: {usn}::{media_server}\r
St: {st}\r
Usn: {usn}::{st}\r
Content-Length: 0\r\n\r\n"
)
}
Expand Down Expand Up @@ -213,12 +212,14 @@ Content-Length: 0\r\n\r\n"
return Ok(());
}

let response = self.generate_ssdp_discover_response();
trace!(content = response, ?addr, "sending SSDP discover response");
self.socket
.send_to(response.as_bytes(), addr)
.await
.context("error sending")?;
if let Ok(st) = std::str::from_utf8(msg.st) {
let response = self.generate_ssdp_discover_response(st);
trace!(content = response, ?addr, "sending SSDP discover response");
self.socket
.send_to(response.as_bytes(), addr)
.await
.context("error sending")?;
}

Ok(())
}
Expand Down

0 comments on commit ef99380

Please sign in to comment.