1
1
use async_h1:: { server, Body } ;
2
2
use async_std:: prelude:: * ;
3
- use async_std:: { io, net, task} ;
3
+ use async_std:: net;
4
+ use async_std:: task;
4
5
5
6
fn main ( ) -> Result < ( ) , async_h1:: Exception > {
6
7
task:: block_on ( async {
@@ -9,26 +10,12 @@ fn main() -> Result<(), async_h1::Exception> {
9
10
let mut incoming = listener. incoming ( ) ;
10
11
11
12
while let Some ( stream) = incoming. next ( ) . await {
12
- // task::spawn(async move {
13
- // let stream = stream?;
14
- // let (reader, writer) = &mut (&stream, &stream);
15
- // let req = server::decode(reader).await?;
16
- // if let server::OptionalRequest::Request(req) = req {
17
- // // dbg!(req);
18
- // let body = Body::from_string("hello chashu".to_owned());
19
- // let mut res = server::encode(http::Response::new(body)).await?;
20
- // io::copy(&mut res, writer).await?;
21
- // }
22
- // Ok::<(), async_h1::Exception>(())
23
- // });
24
13
task:: spawn ( async {
25
14
let stream = stream?;
26
15
let ( reader, writer) = & mut ( & stream, & stream) ;
27
- server:: connect ( reader, writer, |req| {
28
- async {
29
- let body = Body :: from_string ( "hello chashu" . to_owned ( ) ) ;
30
- Ok ( http:: Response :: new ( body) )
31
- }
16
+ server:: connect ( reader, writer, |_| async {
17
+ let body = Body :: from_string ( "hello chashu" . to_owned ( ) ) ;
18
+ Ok ( http:: Response :: new ( body) )
32
19
} )
33
20
. await
34
21
} ) ;
0 commit comments