mod error;
mod io;
mod processor;
mod types;
pub use error::HttpHeaderError;
pub use io::{HttpResponseHeadReadError, read_response_head};
pub use processor::HttpHeaderProcessor;
pub use types::{HttpHeaderParseState, HttpResponseHead};
pub fn find_header_end(bytes: &[u8]) -> Option<usize> {
bytes.windows(4).position(|window| window == b"\r\n\r\n")
}
pub fn parse_response_head(bytes: &[u8]) -> Result<HttpResponseHead, HttpHeaderError> {
let mut processor = HttpHeaderProcessor::new();
match processor.feed(bytes) {
HttpHeaderParseState::Complete => processor.get_result(),
HttpHeaderParseState::Error(message) => Err(HttpHeaderError(message.clone())),
HttpHeaderParseState::ParsingStatusLine | HttpHeaderParseState::ParsingHeaders => Err(
HttpHeaderError("Incomplete HTTP response headers".to_string()),
),
}
}
#[cfg(test)]
mod tests;