@@ -22,6 +22,7 @@ pub enum HttpMethod {
22
22
OPTIONS ,
23
23
TRACE ,
24
24
CONNECT ,
25
+ Other ( String ) ,
25
26
}
26
27
27
28
impl HttpMethod {
@@ -36,7 +37,7 @@ impl HttpMethod {
36
37
"OPTIONS" => HttpMethod :: OPTIONS ,
37
38
"TRACE" => HttpMethod :: TRACE ,
38
39
"CONNECT" => HttpMethod :: CONNECT ,
39
- _ => panic ! ( "Invalid HTTP method" ) ,
40
+ _ => Self :: Other ( method. to_string ( ) ) ,
40
41
}
41
42
}
42
43
pub fn to_str ( & self ) -> & str {
@@ -50,6 +51,7 @@ impl HttpMethod {
50
51
HttpMethod :: OPTIONS => "OPTIONS" ,
51
52
HttpMethod :: TRACE => "TRACE" ,
52
53
HttpMethod :: CONNECT => "CONNECT" ,
54
+ HttpMethod :: Other ( method) => method. as_str ( ) ,
53
55
}
54
56
}
55
57
}
@@ -475,8 +477,9 @@ fn test_http_parser() {
475
477
fn test_http_response_maker ( ) {
476
478
let response = Hteapot :: response_maker ( HttpStatus :: IAmATeapot , "Hello, World!" , None ) ;
477
479
let response = String :: from_utf8 ( response) . unwrap ( ) ;
478
- let expected_response = "HTTP/1.1 418 I'm a teapot\r \n Content-Length: 13\r \n Server: HTeaPot/0.2.5\r \n \r \n Hello, World!\r \n " . split ( "\r \n " ) ;
479
- for item in expected_response. into_iter ( ) {
480
+ let expected_response = format ! ( "HTTP/1.1 418 I'm a teapot\r \n Content-Length: 13\r \n Server: HTeaPot/{}\r \n \r \n Hello, World!\r \n " , VERSION ) ;
481
+ let expected_response_list = expected_response. split ( "\r \n " ) ;
482
+ for item in expected_response_list. into_iter ( ) {
480
483
assert ! ( response. contains( item) ) ;
481
484
}
482
485
}
0 commit comments