1

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?

Samuel
  • 547
  • 1
  • 3
  • 14

1 Answers1

0

This issue is resolved. If you switch to actix skipping in a track works without a problem.

So I start two webservers:

  1. rocket.launch() is executed as the last statement.
  2. actix is spawned before.
#[actix_web::main]
async fn actix() -> std::io::Result<()> {
    HttpServer::new(|| App::new().service(fs::Files::new
        ("/podcasts", "podcasts").show_files_listing()))
        .bind(("0.0.0.0", 8080))?
        .run()
        .await
}

Actix seems more polished - so I am going to switch to actix in the long term as it serves files correctly and also has websocket support.

Samuel
  • 547
  • 1
  • 3
  • 14