File tree Expand file tree Collapse file tree 2 files changed +18
-11
lines changed Expand file tree Collapse file tree 2 files changed +18
-11
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 @@ -29,29 +29,26 @@ impl Handler for Echo {
29
29
( & Get , "/" ) | ( & Get , "/echo" ) => {
30
30
let out = b"Try POST /echo" ;
31
31
32
- res. headers . set ( ContentLength ( out. len ( ) ) ) ;
32
+ res. headers_mut ( ) . 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
- <<<<<<< Updated upstream
40
- res. status = hyper:: status:: NotFound ;
41
- try_continue ! ( res. end( ) ) ;
42
- =======
43
40
* res. status_mut ( ) = hyper:: status:: NotFound ;
44
41
try_continue ! ( res. start( ) . and_then( |res| res. end( ) ) ) ;
45
- >>>>>>> Stashed changes
46
42
continue ;
47
43
}
48
44
} ,
49
45
_ => {
50
- try_continue ! ( res. end( ) ) ;
51
- continue ;
46
+ try_continue ! ( res. start ( ) . and_then ( |res| res . end( ) ) ) ;
47
+ continue ;
52
48
}
53
49
} ;
54
50
51
+ let mut res = try_continue ! ( res. start( ) ) ;
55
52
try_continue ! ( copy( & mut req, & mut res) ) ;
56
53
try_continue ! ( res. end( ) ) ;
57
54
}
You can’t perform that action at this time.
0 commit comments