Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mediaserver response proper st #218

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ create-target-docker:
cp -lf target/armv7-unknown-linux-musleabihf/release-github/rqbit target/docker/linux/arm/v7/rqbit && \
cp docker/Dockerfile target/Docker

@PHONE: docker-build-prereqs
docker-build-prereqs: release-linux-aarch64 release-linux-x86_64 release-linux-armv7

@PHONY: docker-build
docker-build: create-target-docker
docker build \
Expand Down
22 changes: 11 additions & 11 deletions crates/upnp-serve/src/ssdp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ impl SsdpRunner {
#[cfg(not(target_os = "windows"))]
sock.set_reuse_port(true)
.context("error setting SO_REUSEPORT")?;
#[cfg(target_os = "windows")]
sock.set_reuse_address(true)
.context("error setting SO_REUSEADDR")?;

Expand Down Expand Up @@ -153,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 @@ -214,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