1#![feature(test)]
2
3use std::marker::Unpin;
4
5use tokio_util::codec::Framed;
6use tokio::stream::StreamExt;
7use tokio::io::{
8 AsyncRead,
9 AsyncWrite,
10};
11
12pub mod codec;
13pub use codec::HttpCodec;
14
15pub mod error;
16pub use error::HttpResult;
17pub use error::HttpError;
18
19pub mod request;
20pub use request::Request;
21
22pub mod method;
23pub use method::Method;
24
25#[derive(Debug)]
26pub struct Http<S> {
27 pub transport: Framed<S, HttpCodec>,
28}
29
30impl<S> Http<S>
31where
32 S: AsyncRead + AsyncWrite + Unpin,
33{
34 pub fn new(stream: S) -> Self {
35 let transport = Framed::new(stream, HttpCodec::default());
36
37 Self {
38 transport,
39 }
40 }
41
42 pub async fn next(&mut self) -> Option<Request> {
43 if let Some(Ok(req)) = self.transport.next().await {
44 return Some(req)
45 }
46
47 None
48 }
49}