From d20081d9a1acaab2b1b696eedee91a79018bd611 Mon Sep 17 00:00:00 2001 From: Tangent 128 Date: Tue, 26 Sep 2017 02:21:32 -0400 Subject: [PATCH] Serve single, unparsed video file. --- src/bin/loop_server.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/bin/loop_server.rs b/src/bin/loop_server.rs index 415141d..88c85b0 100644 --- a/src/bin/loop_server.rs +++ b/src/bin/loop_server.rs @@ -3,19 +3,20 @@ extern crate hyper; extern crate lab_ebml; use futures::future::FutureResult; -use futures::stream::{iter, Stream}; +use futures::stream::{once, Stream}; use lab_ebml::chunk::Chunk; use hyper::{Get, StatusCode}; +use hyper::header::ContentType; use hyper::server::{Http, Request, Response, Service}; use std::env::args; use std::rc::Rc; use std::net::ToSocketAddrs; -//const SRC_FILE: &'static [u8] = include_bytes!("../data/test1.webm"); +const SRC_FILE: &'static [u8] = include_bytes!("../data/test1.webm"); struct WebmServer; -type BodyStream = Box, Error = hyper::Error>>; +type BodyStream = Box, Error = hyper::Error>>; impl Service for WebmServer { type Request = Request; @@ -25,13 +26,9 @@ impl Service for WebmServer { fn call(&self, req: Request) -> Self::Future { let response = match (req.method(), req.path()) { (&Get, "/loop") => { - let pieces = vec![ - Chunk::Headers {bytes: Rc::new("<")}, - Chunk::Headers {bytes: Rc::new("Insert WebM stream here")}, - Chunk::ClusterBody {bytes: Rc::new(">")} - ]; - let stream: BodyStream = Box::new(iter(pieces.into_iter().map(|x| Ok(x)))); + let stream: BodyStream = Box::new(once(Ok(Chunk::Headers {bytes: Rc::new(SRC_FILE)}))); Response::new() + .with_header(ContentType("video/webm".parse().unwrap())) .with_body(stream) }, _ => {