@@ -7,10 +7,8 @@ use std::io::util::copy;
7
7
use std:: io:: net:: ip:: Ipv4Addr ;
8
8
9
9
use hyper:: { Get , Post } ;
10
- use hyper:: server:: { Server , Handler , Incoming } ;
11
10
use hyper:: header:: common:: ContentLength ;
12
-
13
- struct Echo ;
11
+ use hyper:: server:: { Server , Incoming } ;
14
12
15
13
macro_rules! try_continue(
16
14
( $e: expr) => { {
@@ -21,41 +19,39 @@ macro_rules! try_continue(
21
19
} }
22
20
)
23
21
24
- impl Handler for Echo {
25
- fn handle ( self , mut incoming : Incoming ) {
26
- for ( mut req, mut res) in incoming {
27
- match req. uri {
28
- hyper:: uri:: AbsolutePath ( ref path) => match ( & req. method , path. as_slice ( ) ) {
29
- ( & Get , "/" ) | ( & Get , "/echo" ) => {
30
- let out = b"Try POST /echo" ;
31
-
32
- res. headers_mut ( ) . set ( ContentLength ( out. len ( ) ) ) ;
33
- let mut res = try_continue ! ( res. start( ) ) ;
34
- try_continue ! ( res. write( out) ) ;
35
- try_continue ! ( res. end( ) ) ;
36
- continue ;
37
- } ,
38
- ( & Post , "/echo" ) => ( ) , // fall through, fighting mutable borrows
39
- _ => {
40
- * res. status_mut ( ) = hyper:: status:: NotFound ;
41
- try_continue ! ( res. start( ) . and_then( |res| res. end( ) ) ) ;
42
- continue ;
43
- }
22
+ fn echo ( mut incoming : Incoming ) {
23
+ for ( mut req, mut res) in incoming {
24
+ match req. uri {
25
+ hyper:: uri:: AbsolutePath ( ref path) => match ( & req. method , path. as_slice ( ) ) {
26
+ ( & Get , "/" ) | ( & Get , "/echo" ) => {
27
+ let out = b"Try POST /echo" ;
28
+
29
+ res. headers_mut ( ) . set ( ContentLength ( out. len ( ) ) ) ;
30
+ let mut res = try_continue ! ( res. start( ) ) ;
31
+ try_continue ! ( res. write( out) ) ;
32
+ try_continue ! ( res. end( ) ) ;
33
+ continue ;
44
34
} ,
35
+ ( & Post , "/echo" ) => ( ) , // fall through, fighting mutable borrows
45
36
_ => {
37
+ * res. status_mut ( ) = hyper:: status:: NotFound ;
46
38
try_continue ! ( res. start( ) . and_then( |res| res. end( ) ) ) ;
47
39
continue ;
48
40
}
49
- } ;
50
-
51
- let mut res = try_continue ! ( res. start( ) ) ;
52
- try_continue ! ( copy( & mut req, & mut res) ) ;
53
- try_continue ! ( res. end( ) ) ;
54
- }
41
+ } ,
42
+ _ => {
43
+ try_continue ! ( res. start( ) . and_then( |res| res. end( ) ) ) ;
44
+ continue ;
45
+ }
46
+ } ;
47
+
48
+ let mut res = try_continue ! ( res. start( ) ) ;
49
+ try_continue ! ( copy( & mut req, & mut res) ) ;
50
+ try_continue ! ( res. end( ) ) ;
55
51
}
56
52
}
57
53
58
54
fn main ( ) {
59
55
let server = Server :: http ( Ipv4Addr ( 127 , 0 , 0 , 1 ) , 1337 ) ;
60
- server. listen ( Echo ) . unwrap ( ) ;
56
+ server. listen ( echo ) . unwrap ( ) ;
61
57
}
0 commit comments