Use trait objects and dynamic dispatch to abstract over NetworkStream
Server and client benchmarks show that this makes very little difference in performance and using dynamic dispatch here is significantly more ergonomic. This also bounds NetworkStream with Send to prevent incorrect implementations. Allows the implementation of mock streams for testing and flexibility. Fixes #5
This commit is contained in:
@@ -13,7 +13,7 @@ use hyper::header::common::ContentLength;
|
||||
use hyper::net::{HttpStream, HttpAcceptor};
|
||||
|
||||
trait ConcurrentHandler: Send + Sync {
|
||||
fn handle(&self, req: Request, res: Response<Fresh, HttpStream>);
|
||||
fn handle(&self, req: Request, res: Response<Fresh>);
|
||||
}
|
||||
|
||||
struct Concurrent<H: ConcurrentHandler> { handler: Arc<H> }
|
||||
@@ -39,7 +39,7 @@ macro_rules! try_abort(
|
||||
struct Echo;
|
||||
|
||||
impl ConcurrentHandler for Echo {
|
||||
fn handle(&self, mut req: Request, mut res: Response<Fresh, HttpStream>) {
|
||||
fn handle(&self, mut req: Request, mut res: Response<Fresh>) {
|
||||
match req.uri {
|
||||
hyper::uri::AbsolutePath(ref path) => match (&req.method, path.as_slice()) {
|
||||
(&Get, "/") | (&Get, "/echo") => {
|
||||
|
||||
Reference in New Issue
Block a user