diff --git a/crates/librqbit/src/http_api.rs b/crates/librqbit/src/http_api.rs index 360388a..3392bbf 100644 --- a/crates/librqbit/src/http_api.rs +++ b/crates/librqbit/src/http_api.rs @@ -202,13 +202,16 @@ impl HttpApi { }), ) .await?; - let content = match added { - crate::AddTorrentResponse::AlreadyManaged(_, handle) => { - handle.info().torrent_bytes.clone().0 - } - crate::AddTorrentResponse::ListOnly(ListOnlyResponse { torrent_bytes, .. }) => { - torrent_bytes.0 - } + let (info, content) = match added { + crate::AddTorrentResponse::AlreadyManaged(_, handle) => ( + handle.info().info.clone(), + handle.info().torrent_bytes.clone().0, + ), + crate::AddTorrentResponse::ListOnly(ListOnlyResponse { + info, + torrent_bytes, + .. + }) => (info, torrent_bytes.0), crate::AddTorrentResponse::Added(_, _) => { return Err(ApiError::new_from_text( StatusCode::INTERNAL_SERVER_ERROR, @@ -216,7 +219,22 @@ impl HttpApi { )) } }; - Ok(content) + let mut headers = HeaderMap::new(); + headers.insert( + "Content-Type", + HeaderValue::from_static("application/x-bittorrent"), + ); + + if let Some(name) = info.name.as_ref() { + if let Ok(name) = std::str::from_utf8(&name) { + if let Ok(h) = + HeaderValue::from_str(&format!("attachment; filename=\"{}.torrent\"", name)) + { + headers.insert("Content-Disposition", h); + } + } + } + Ok((headers, content)) } async fn torrent_playlist(