From db1731f776e7fe28872f46aee8d1952cc0e86b71 Mon Sep 17 00:00:00 2001 From: Tangent 128 Date: Thu, 21 Sep 2017 00:59:11 -0400 Subject: [PATCH] Experiment with using a Stream for a Response Body --- src/bin/loop_server.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/bin/loop_server.rs b/src/bin/loop_server.rs index 2760854..6bf9669 100644 --- a/src/bin/loop_server.rs +++ b/src/bin/loop_server.rs @@ -3,6 +3,7 @@ extern crate hyper; extern crate lab_ebml; use futures::future::FutureResult; +use futures::stream::{iter, Stream}; use hyper::{Get, StatusCode}; use hyper::server::{Http, Request, Response, Service}; use std::env::args; @@ -12,16 +13,20 @@ use std::net::ToSocketAddrs; struct WebmServer; +type BodyStream = Box>; + impl Service for WebmServer { type Request = Request; - type Response = Response; + type Response = Response; type Error = hyper::Error; - type Future = FutureResult; + type Future = FutureResult; fn call(&self, req: Request) -> Self::Future { let response = match (req.method(), req.path()) { (&Get, "/loop") => { + let pieces = vec!["<", "Insert WebM stream here.", ">"]; + let stream: BodyStream = iter(pieces.into_iter().map(|x| Ok(x))).boxed(); Response::new() - .with_body("") + .with_body(stream) }, _ => { Response::new()