Experiment with using a Stream for a Response Body
This commit is contained in:
parent
ef45728779
commit
db1731f776
1 changed files with 8 additions and 3 deletions
|
@ -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<Stream<Item = &'static str, Error = hyper::Error>>;
|
||||
|
||||
impl Service for WebmServer {
|
||||
type Request = Request;
|
||||
type Response = Response;
|
||||
type Response = Response<BodyStream>;
|
||||
type Error = hyper::Error;
|
||||
type Future = FutureResult<Response, hyper::Error>;
|
||||
type Future = FutureResult<Self::Response, hyper::Error>;
|
||||
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("<Insert WebM stream here>")
|
||||
.with_body(stream)
|
||||
},
|
||||
_ => {
|
||||
Response::new()
|
||||
|
|
Loading…
Add table
Reference in a new issue