Skip to main content

sark_http/h1/head/
mod.rs

1//! HTTP/1 head syntax, framing, and admission.
2
3use core::mem;
4
5use crate::{
6    h1::{
7        field::{self, syntax},
8        framing, switch, target,
9    },
10    payload::response::status,
11    request::span,
12};
13
14mod limit;
15pub mod line;
16pub mod request;
17pub mod response;
18mod state;
19mod tail;
20
21pub use limit::Limit;
22
23#[derive(Clone, Copy, PartialEq, Eq, Debug)]
24pub enum Boundary {
25    Invalid,
26    TooLarge { actual: usize, limit: usize },
27    Span(span::Error),
28}
29
30#[derive(Clone, Copy, PartialEq, Eq, Debug)]
31pub enum Semantic {
32    Status(status::Error),
33    Field(field::Error),
34    Host(target::HostError),
35    Routing(target::Invalid),
36    Authority(target::Error),
37    Connection(field::TokenError),
38    Upgrade(switch::UpgradeError),
39    Admission(framing::RequestError),
40    Transition(switch::Error),
41    Framing(framing::Error),
42}
43
44const _: () = {
45    assert!(mem::size_of::<Boundary>() == 4 * mem::size_of::<usize>());
46    assert!(mem::size_of::<Option<Boundary>>() == mem::size_of::<Boundary>());
47    assert!(!mem::needs_drop::<Boundary>());
48    assert!(mem::size_of::<Semantic>() == 6 * mem::size_of::<usize>());
49    assert!(mem::size_of::<Option<Semantic>>() == mem::size_of::<Semantic>());
50    assert!(!mem::needs_drop::<Semantic>());
51};
52
53#[derive(Clone, Copy, PartialEq, Eq, Debug)]
54pub enum ParseError<E> {
55    Boundary(Boundary),
56    Field(syntax::Error),
57    Semantic(Semantic),
58    Sink(E),
59}
60
61impl<E> ParseError<E> {
62    pub const fn invalid() -> Self {
63        Self::Boundary(Boundary::Invalid)
64    }
65
66    pub const fn too_large(actual: usize, limit: usize) -> Self {
67        Self::Boundary(Boundary::TooLarge { actual, limit })
68    }
69}