leyline-http 0.1.5

HTTP client that impersonates Chrome, Firefox, and Safari on the wire: TLS (JA3/JA4), HTTP/2, and HTTP/3 fingerprints
Documentation
use super::*;

pub(super) enum Encoder {
    Fixed,
    Chunked,
}

impl Encoder {
    pub(super) fn encode(
        &mut self,
        chunk: Bytes,
        out: &mut VecDeque<Bytes>,
    ) -> Result<(), H1PooledError> {
        match self {
            Encoder::Fixed => {
                if !chunk.is_empty() {
                    out.push_back(chunk);
                }
            }
            Encoder::Chunked => {
                if !chunk.is_empty() {
                    out.push_back(Bytes::from(format!("{:X}\r\n", chunk.len())));
                    out.push_back(chunk);
                    out.push_back(Bytes::from_static(b"\r\n"));
                }
            }
        }
        Ok(())
    }

    pub(super) fn finish(&self, out: &mut VecDeque<Bytes>) -> Result<(), H1PooledError> {
        match self {
            Encoder::Fixed => Ok(()),
            Encoder::Chunked => {
                out.push_back(Bytes::from_static(b"0\r\n\r\n"));
                Ok(())
            }
        }
    }
}