Add headers

This commit is contained in:
Igor Katson 2024-08-12 23:59:23 +01:00
parent 5b5352710e
commit 5193153e09
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5

View file

@ -202,13 +202,16 @@ impl HttpApi {
}), }),
) )
.await?; .await?;
let content = match added { let (info, content) = match added {
crate::AddTorrentResponse::AlreadyManaged(_, handle) => { crate::AddTorrentResponse::AlreadyManaged(_, handle) => (
handle.info().torrent_bytes.clone().0 handle.info().info.clone(),
} handle.info().torrent_bytes.clone().0,
crate::AddTorrentResponse::ListOnly(ListOnlyResponse { torrent_bytes, .. }) => { ),
torrent_bytes.0 crate::AddTorrentResponse::ListOnly(ListOnlyResponse {
} info,
torrent_bytes,
..
}) => (info, torrent_bytes.0),
crate::AddTorrentResponse::Added(_, _) => { crate::AddTorrentResponse::Added(_, _) => {
return Err(ApiError::new_from_text( return Err(ApiError::new_from_text(
StatusCode::INTERNAL_SERVER_ERROR, 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( async fn torrent_playlist(