Conditionally insert DLNA headers only if asked for

This commit is contained in:
Igor Katson 2024-09-02 13:19:32 +01:00
parent f96a9024e1
commit 86c68052ef
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5

View file

@ -346,15 +346,28 @@ impl HttpApi {
let mut output_headers = HeaderMap::new(); let mut output_headers = HeaderMap::new();
output_headers.insert("Accept-Ranges", HeaderValue::from_static("bytes")); output_headers.insert("Accept-Ranges", HeaderValue::from_static("bytes"));
output_headers.insert( const DLNA_TRANSFER_MODE: &str = "transferMode.dlna.org";
"transferMode.dlna.org", const DLNA_GET_CONTENT_FEATURES: &str = "getcontentFeatures.dlna.org";
HeaderValue::from_static("Streaming"), const DLNA_CONTENT_FEATURES: &str = "contentFeatures.dlna.org";
);
output_headers.insert( if headers
"contentFeatures.dlna.org", .get(DLNA_TRANSFER_MODE)
HeaderValue::from_static("DLNA.ORG_OP=01"), .map(|v| matches!(v.as_bytes(), b"Streaming" | b"streaming"))
); .unwrap_or(false)
{
output_headers.insert(DLNA_TRANSFER_MODE, HeaderValue::from_static("Streaming"));
}
if headers
.get(DLNA_GET_CONTENT_FEATURES)
.map(|v| v.as_bytes() == b"1")
.unwrap_or(false)
{
output_headers.insert(
DLNA_CONTENT_FEATURES,
HeaderValue::from_static("DLNA.ORG_OP=01"),
);
}
if let Ok(mime) = state.torrent_file_mime_type(idx, file_id) { if let Ok(mime) = state.torrent_file_mime_type(idx, file_id) {
output_headers.insert( output_headers.insert(