use bytes::Bytes;
use crate::error::HttpError;
use crate::h1_conn::H1StreamingResponse;
use crate::h2_conn::H2StreamingResponse;
pub enum StreamingResponse<'a> {
H2(H2StreamingResponse<'a>),
H1(H1StreamingResponse<'a>),
}
impl StreamingResponse<'_> {
pub fn status(&self) -> u16 {
match self {
Self::H2(s) => s.status(),
Self::H1(s) => s.status(),
}
}
pub fn headers(&self) -> &[(String, String)] {
match self {
Self::H2(s) => s.headers(),
Self::H1(s) => s.headers(),
}
}
pub fn header(&self, name: &str) -> Option<&str> {
match self {
Self::H2(s) => s.header(name),
Self::H1(s) => s.header(name),
}
}
pub async fn next_chunk(&mut self) -> Result<Option<Bytes>, HttpError> {
match self {
Self::H2(s) => s.next_chunk().await,
Self::H1(s) => s.next_chunk().await,
}
}
}