I have the problem that my server does not respond with a 206 Partial Content as described here. Changing the audio elements attribute currentTime only works in Firefox but not in Chrome. I implemented an own static file hosting with this code:
use std::path::{Path, PathBuf};
use rocket::{response, Response};
use rocket::http::Status;
use rocket::response::{NamedFile, Responder};
pub struct CachedFile(NamedFile);
use rocket::Request;
impl<'r> Responder<'r> for CachedFile {
fn respond_to(self, req: &Request) -> response::Result<'r> {
Response::build_from(self.0.respond_to(req)?)
.status(Status::PartialContent)
.raw_header("Connection", "keep-alive")
.ok()
}
}
#[get("/<file..>")]
pub fn files(file: PathBuf) -> Option<CachedFile> {
let path = Path::new("podcasts\\").join(file);
println!("path: {:?}", path);
NamedFile::open(path)
.ok()
.map(|nf| CachedFile(nf))
}
When executing a get on one of the existing mp3 files I get "An existing connection was terminated by software control by the host computer.". Did somebody succeed in configuring rocket to have persistent connections? Is there any other way to get changing current time in Chrome to work?