<commit_before>mod request;
mod protocol;
mod context;
mod parser;
mod body;
mod response;

use netbuf::Buf;
use hyper::method::Method::Head;
use hyper::version::HttpVersion as Version;

use self::response::{NOT_IMPLEMENTED_HEAD, NOT_IMPLEMENTED};

pub use self::request::Head;
pub use self::context::Context;
pub use self::protocol::{RecvMode, Server};
pub use self::parser::Parser;

// TODO(tailhook) MAX_HEADERS_SIZE can be moved to Context
// (i.e. made non-constant), but it's more of a problem for MAX_HEADERS_NUM
// because that would mean we can't allocate array of headers on the stack
// so performance will degrade. Customizing MAX_HEADERS_SIZE is not very
// useful on it's own

/// Note httparse requires we preallocate array of this size so be wise
pub const MAX_HEADERS_NUM: usize = 256;
/// This one is not preallocated, but too large buffer is of limited use
/// because of previous parameter.
pub const MAX_HEADERS_SIZE: usize = 16384;
/// Maximum length of chunk size line. it would be okay with 12 bytes, but in
/// theory there might be some extensions which we probably should skip
///
/// Note: we don't have a limit on chunk body size. In buffered request mode
/// it's limited by either memory or artificial limit returned from handler.
/// In unbuffered mode we can process chunk of unlimited size as long as
/// request handler is able to handle it.
pub const MAX_CHUNK_HEAD: usize = 128;


#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum ResponseBody {
    Normal,
    Ignored,  // HEAD requests, 304 responses
    Denied,  // 101, 204 responses (100 too if it is used here)
}


#[derive(Debug)]
enum ResponseImpl {
    /// Nothing has been sent
    Start { version: Version, body: ResponseBody },
    /// Status line is already in the buffer
    Headers { body: ResponseBody,
              content_length: Option<u64>, chunked: bool },
    ZeroBodyResponse,  // When response body is Denied
    IgnoredBody, // When response body is Ignored
    FixedSizeBody(u64),
    ChunkedBody,
    Done,
}

pub struct Response<'a>(&'a mut Buf, ResponseImpl);

impl ResponseImpl {<commit_msg>Changed the order of fields to make state machine 8 bytes smaller<commit_after>mod request;
mod protocol;
mod context;
mod parser;
mod body;
mod response;

use netbuf::Buf;
use hyper::method::Method::Head;
use hyper::version::HttpVersion as Version;

use self::response::{NOT_IMPLEMENTED_HEAD, NOT_IMPLEMENTED};

pub use self::request::Head;
pub use self::context::Context;
pub use self::protocol::{RecvMode, Server};
pub use self::parser::Parser;

// TODO(tailhook) MAX_HEADERS_SIZE can be moved to Context
// (i.e. made non-constant), but it's more of a problem for MAX_HEADERS_NUM
// because that would mean we can't allocate array of headers on the stack
// so performance will degrade. Customizing MAX_HEADERS_SIZE is not very
// useful on it's own

/// Note httparse requires we preallocate array of this size so be wise
pub const MAX_HEADERS_NUM: usize = 256;
/// This one is not preallocated, but too large buffer is of limited use
/// because of previous parameter.
pub const MAX_HEADERS_SIZE: usize = 16384;
/// Maximum length of chunk size line. it would be okay with 12 bytes, but in
/// theory there might be some extensions which we probably should skip
///
/// Note: we don't have a limit on chunk body size. In buffered request mode
/// it's limited by either memory or artificial limit returned from handler.
/// In unbuffered mode we can process chunk of unlimited size as long as
/// request handler is able to handle it.
pub const MAX_CHUNK_HEAD: usize = 128;


#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum ResponseBody {
    Normal,
    Ignored,  // HEAD requests, 304 responses
    Denied,  // 101, 204 responses (100 too if it is used here)
}


#[derive(Debug)]
enum ResponseImpl {
    /// Nothing has been sent
    Start { version: Version, body: ResponseBody },
    /// Status line is already in the buffer
    Headers { body: ResponseBody, chunked: bool,
              content_length: Option<u64> },
    ZeroBodyResponse,  // When response body is Denied
    IgnoredBody, // When response body is Ignored
    FixedSizeBody(u64),
    ChunkedBody,
    Done,
}

pub struct Response<'a>(&'a mut Buf, ResponseImpl);

impl ResponseImpl {
{'fraction_non_alphanumeric': 0.09252336448598131, 'fraction_numerical': 0.013785046728971963, 'mean_word_length': 3.7993273542600896, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5898854', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1210, 'n_words': 549}