#![feature(test)]

use std::marker::Unpin;

use tokio_util::codec::Framed;
use tokio::stream::StreamExt;
use tokio::io::{
    AsyncRead,
    AsyncWrite,
};

pub mod codec;
pub use codec::HttpCodec;

pub mod error;
pub use error::HttpResult;
pub use error::HttpError;

pub mod request;
pub use request::Request;

pub mod method;
pub use method::Method;

pub struct Http<S> {
    transport: Framed<S, HttpCodec>,
}

impl<S> Http<S>
where
    S: AsyncRead + AsyncWrite + Unpin,
{
    pub fn new(stream: S) -> Self {
        let transport = Framed::new(stream, HttpCodec::default());

        Self {
            transport,
        }
    }

    pub async fn next(&mut self) -> Option<Request> {
        if let Some(Ok(req)) = self.transport.next().await {
            return Some(req)
        }

        None
    }
}
