http1_spec/
body_parser.rs1use core::num::ParseIntError;
2use std::io::{BufRead, Error as IoError, ErrorKind as IoErrorKind};
3
4#[derive(Debug, PartialEq, Eq)]
8pub enum BodyParseOutput {
9 Completed(usize),
10 Partial(usize),
11}
12
13#[derive(Debug)]
14pub enum BodyParseError {
15 ReadError(IoError),
16 TooLongChunksOfLength,
17 InvalidChunksOfLength(Option<ParseIntError>),
18 TooLongChunksOfCRLF,
19 InvalidCRLF,
20}
21impl core::fmt::Display for BodyParseError {
22 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
23 write!(f, "{self:?}")
24 }
25}
26impl std::error::Error for BodyParseError {}
27impl From<BodyParseError> for IoError {
28 fn from(err: BodyParseError) -> IoError {
29 IoError::new(IoErrorKind::InvalidInput, err.to_string())
30 }
31}
32
33pub trait BodyParser {
37 fn parse<R: BufRead>(
38 &mut self,
39 r: &mut R,
40 body_buf: &mut Vec<u8>,
41 ) -> Result<BodyParseOutput, BodyParseError>;
42}