File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change
1
+ #![ feature( macro_rules) ]
1
2
extern crate curl;
2
3
extern crate http;
3
4
extern crate hyper;
@@ -13,10 +14,19 @@ fn listen() -> hyper::server::Listening {
13
14
server. listen ( handle) . unwrap ( )
14
15
}
15
16
17
+ macro_rules! try_continue(
18
+ ( $e: expr) => { {
19
+ match $e {
20
+ Ok ( v) => v,
21
+ Err ( ..) => continue
22
+ }
23
+ } } )
24
+
16
25
fn handle ( mut incoming : Incoming ) {
17
- for ( _, mut res) in incoming {
18
- res. write ( b"Benchmarking hyper vs others!" ) . unwrap ( ) ;
19
- res. end ( ) . unwrap ( ) ;
26
+ for ( _, res) in incoming {
27
+ let mut res = try_continue ! ( res. start( ) ) ;
28
+ try_continue ! ( res. write( b"Benchmarking hyper vs others!" ) )
29
+ try_continue ! ( res. end( ) ) ;
20
30
}
21
31
}
22
32
Original file line number Diff line number Diff line change @@ -30,23 +30,25 @@ impl Handler for Echo {
30
30
let out = b"Try POST /echo" ;
31
31
32
32
res. headers . set ( ContentLength ( out. len ( ) ) ) ;
33
+ let mut res = try_continue ! ( res. start( ) ) ;
33
34
try_continue ! ( res. write( out) ) ;
34
35
try_continue ! ( res. end( ) ) ;
35
36
continue ;
36
37
} ,
37
38
( & Post , "/echo" ) => ( ) , // fall through, fighting mutable borrows
38
39
_ => {
39
40
res. status = hyper:: status:: NotFound ;
40
- try_continue ! ( res. end( ) ) ;
41
+ try_continue ! ( res. start ( ) . and_then ( |res| res . end( ) ) ) ;
41
42
continue ;
42
43
}
43
44
} ,
44
45
_ => {
45
- try_continue ! ( res. end( ) ) ;
46
- continue ;
46
+ try_continue ! ( res. start ( ) . and_then ( |res| res . end( ) ) ) ;
47
+ continue ;
47
48
}
48
49
} ;
49
50
51
+ let mut res = try_continue ! ( res. start( ) ) ;
50
52
try_continue ! ( copy( & mut req, & mut res) ) ;
51
53
try_continue ! ( res. end( ) ) ;
52
54
}
You can’t perform that action at this time.
0 commit comments