Skip to content

Commit

Permalink
Conditionally insert DLNA headers only if asked for
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatson committed Sep 2, 2024
1 parent f96a902 commit b5c56ce
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions crates/librqbit/src/http_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bencode::AsDisplay;
use buffers::ByteBuf;
use futures::future::BoxFuture;
use futures::{FutureExt, TryStreamExt};
use http::{HeaderMap, HeaderValue, StatusCode};
use http::{HeaderMap, HeaderName, HeaderValue, StatusCode};
use itertools::Itertools;

use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -346,15 +346,28 @@ impl HttpApi {
let mut output_headers = HeaderMap::new();
output_headers.insert("Accept-Ranges", HeaderValue::from_static("bytes"));

output_headers.insert(
"transferMode.dlna.org",
HeaderValue::from_static("Streaming"),
);
const DLNA_TRANSFER_MODE: &str = "transferMode.dlna.org";
const DLNA_GET_CONTENT_FEATURES: &str = "getcontentFeatures.dlna.org";
const DLNA_CONTENT_FEATURES: &str = "contentFeatures.dlna.org";

output_headers.insert(
"contentFeatures.dlna.org",
HeaderValue::from_static("DLNA.ORG_OP=01"),
);
if headers
.get(DLNA_TRANSFER_MODE)
.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) {
output_headers.insert(
Expand Down

0 comments on commit b5c56ce

Please sign in to comment.