@@ -8,34 +8,23 @@ use async_std::net::{self, TcpStream};
8
8
use async_std:: prelude:: * ;
9
9
use async_std:: task:: { self , Context , Poll } ;
10
10
use http_types:: headers:: { HeaderName , HeaderValue } ;
11
- use http_types:: { Response , StatusCode } ;
11
+ use http_types:: { Response , StatusCode , Request } ;
12
12
13
13
async fn accept ( addr : String , stream : TcpStream ) -> Result < ( ) , async_h1:: Exception > {
14
14
// println!("starting new connection from {}", stream.peer_addr()?);
15
15
16
16
// TODO: Delete this line when we implement `Clone` for `TcpStream`.
17
17
let stream = Stream ( Arc :: new ( stream) ) ;
18
18
19
- server:: accept ( & addr, stream. clone ( ) , stream, |req| {
20
- async {
21
- let mut body = vec ! [ ] ;
22
- req. read_to_end ( & mut body) . await ?;
23
-
24
- let mut resp = Response :: new ( StatusCode :: Ok ) ;
25
- resp. insert_header (
26
- HeaderName :: from_str ( "Content-Type" ) ?,
27
- HeaderValue :: from_str ( "text/plain" ) ?,
28
- ) ?;
29
- resp. set_body ( "Hello" ) ;
19
+ server:: accept ( & addr, stream. clone ( ) , stream, endpoint) . await
20
+ // let method = req.method();
21
+ // async {
22
+ // Ok("hello world".into())
23
+ // }}).await
24
+ }
30
25
31
- // To try chunked encoding, replace `set_body_string` with the following method call
32
- // .set_body(io::Cursor::new(vec![
33
- // 0x48u8, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6F, 0x72, 0x6C, 0x64, 0x21,
34
- // ]));
35
- Ok ( resp)
36
- }
37
- } )
38
- . await
26
+ async fn endpoint ( req : & mut Request ) -> Result < Response , async_h1:: Exception > {
27
+ Ok ( "hello world" . into ( ) )
39
28
}
40
29
41
30
fn main ( ) -> Result < ( ) , async_h1:: Exception > {
0 commit comments