Merge pull request #162 from izderadicka/add_content_type_to_stream

Add content type to streams
This commit is contained in:
Igor Katson 2024-08-02 12:56:13 +01:00 committed by GitHub
commit c86e663f24
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 61 additions and 7 deletions

View file

@ -167,6 +167,13 @@ impl HttpApi {
let mut output_headers = HeaderMap::new();
output_headers.insert("Accept-Ranges", HeaderValue::from_static("bytes"));
if let Ok(mime) = state.torrent_file_mime_type(idx, file_id) {
output_headers.insert(
http::header::CONTENT_TYPE,
HeaderValue::from_str(mime).context("bug - invalid MIME")?,
);
}
let range_header = headers.get(http::header::RANGE);
trace!(torrent_id=idx, file_id=file_id, range=?range_header, "request for HTTP stream");
@ -199,12 +206,12 @@ impl HttpApi {
))
.context("bug")?,
);
} else {
output_headers.insert(
http::header::CONTENT_LENGTH,
HeaderValue::from_str(&format!("{}", stream.len())).context("bug")?,
);
}
} else {
output_headers.insert(
http::header::CONTENT_LENGTH,
HeaderValue::from_str(&format!("{}", stream.len())).context("bug")?,
);
}
let s = tokio_util::io::ReaderStream::new(stream);