Skip to content

Commit fbc1c46

Browse files
committed
patches
Signed-off-by: Yoshua Wuyts <[email protected]>
1 parent bbf51eb commit fbc1c46

File tree

2 files changed

+10
-21
lines changed

2 files changed

+10
-21
lines changed

examples/server.rs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,23 @@ use async_std::net::{self, TcpStream};
88
use async_std::prelude::*;
99
use async_std::task::{self, Context, Poll};
1010
use http_types::headers::{HeaderName, HeaderValue};
11-
use http_types::{Response, StatusCode};
11+
use http_types::{Response, StatusCode, Request};
1212

1313
async fn accept(addr: String, stream: TcpStream) -> Result<(), async_h1::Exception> {
1414
// println!("starting new connection from {}", stream.peer_addr()?);
1515

1616
// TODO: Delete this line when we implement `Clone` for `TcpStream`.
1717
let stream = Stream(Arc::new(stream));
1818

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+
}
3025

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())
3928
}
4029

4130
fn main() -> Result<(), async_h1::Exception> {

src/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub async fn accept<R, W, F, Fut>(
3131
where
3232
R: Read + Unpin + Send + 'static,
3333
W: Write + Unpin,
34-
F: Fn(&mut Request) -> Fut,
34+
F: for<'a> Fn(&'a mut Request) -> Fut,
3535
Fut: Future<Output = Result<Response, Exception>>,
3636
{
3737
// TODO: make configurable

0 commit comments

Comments
 (0)