Fix concurrent server example for new Response representation.
This commit is contained in:
		| @@ -8,11 +8,11 @@ use std::io::net::ip::Ipv4Addr; | |||||||
| use std::sync::Arc; | use std::sync::Arc; | ||||||
|  |  | ||||||
| use hyper::{Get, Post}; | use hyper::{Get, Post}; | ||||||
| use hyper::server::{Server, Handler, Incoming, Request, Response}; | use hyper::server::{Server, Handler, Incoming, Request, Response, Fresh}; | ||||||
| use hyper::header::common::ContentLength; | use hyper::header::common::ContentLength; | ||||||
|  |  | ||||||
| trait ConcurrentHandler: Send + Sync { | trait ConcurrentHandler: Send + Sync { | ||||||
|     fn handle(&self, req: Request, res: Response); |     fn handle(&self, req: Request, res: Response<Fresh>); | ||||||
| } | } | ||||||
|  |  | ||||||
| struct Concurrent<H: ConcurrentHandler> { handler: Arc<H> } | struct Concurrent<H: ConcurrentHandler> { handler: Arc<H> } | ||||||
| @@ -38,29 +38,31 @@ macro_rules! try_abort( | |||||||
| struct Echo; | struct Echo; | ||||||
|  |  | ||||||
| impl ConcurrentHandler for Echo { | impl ConcurrentHandler for Echo { | ||||||
|     fn handle(&self, mut req: Request, mut res: Response) { |     fn handle(&self, mut req: Request, mut res: Response<Fresh>) { | ||||||
|         match req.uri { |         match req.uri { | ||||||
|             hyper::uri::AbsolutePath(ref path) => match (&req.method, path.as_slice()) { |             hyper::uri::AbsolutePath(ref path) => match (&req.method, path.as_slice()) { | ||||||
|                 (&Get, "/") | (&Get, "/echo") => { |                 (&Get, "/") | (&Get, "/echo") => { | ||||||
|                     let out = b"Try POST /echo"; |                     let out = b"Try POST /echo"; | ||||||
|  |  | ||||||
|                     res.headers.set(ContentLength(out.len())); |                     res.headers_mut().set(ContentLength(out.len())); | ||||||
|  |                     let mut res = try_abort!(res.start()); | ||||||
|                     try_abort!(res.write(out)); |                     try_abort!(res.write(out)); | ||||||
|                     try_abort!(res.end()); |                     try_abort!(res.end()); | ||||||
|                     return; |                     return; | ||||||
|                 }, |                 }, | ||||||
|                 (&Post, "/echo") => (), // fall through, fighting mutable borrows |                 (&Post, "/echo") => (), // fall through, fighting mutable borrows | ||||||
|                 _ => { |                 _ => { | ||||||
|                     res.status = hyper::status::NotFound; |                     *res.status_mut() = hyper::status::NotFound; | ||||||
|                     try_abort!(res.end()); |                     try_abort!(res.start().and_then(|res| res.end())); | ||||||
|                     return; |                     return; | ||||||
|                 } |                 } | ||||||
|             }, |             }, | ||||||
|             _ => { |             _ => { | ||||||
|                 try_abort!(res.end()); |                 try_abort!(res.start().and_then(|res| res.end())); | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |         let mut res = try_abort!(res.start()); | ||||||
|         try_abort!(copy(&mut req, &mut res)); |         try_abort!(copy(&mut req, &mut res)); | ||||||
|         try_abort!(res.end()); |         try_abort!(res.end()); | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user