sozu_lib/protocol/
mod.rs

1pub mod h2;
2pub mod kawa_h1;
3pub mod pipe;
4pub mod proxy_protocol;
5pub mod rustls;
6
7use std::{cell::RefCell, rc::Rc};
8
9use mio::Token;
10use sozu_command::ready::Ready;
11
12pub use crate::protocol::{
13    http::Http, kawa_h1 as http, pipe::Pipe, proxy_protocol::send::SendProxyProtocol,
14    rustls::TlsHandshake,
15};
16use crate::{
17    L7Proxy, ProxySession, SessionIsToBeClosed, SessionMetrics, SessionResult, StateResult,
18};
19
20/// All States should satisfy this trait in order to receive and handle Session events
21pub trait SessionState {
22    /// if a session received an event or can still execute, the event loop will
23    /// call this method. Its result indicates if it can still execute or if the
24    /// session can be closed
25    fn ready(
26        &mut self,
27        session: Rc<RefCell<dyn ProxySession>>,
28        proxy: Rc<RefCell<dyn L7Proxy>>,
29        metrics: &mut SessionMetrics,
30    ) -> SessionResult;
31    /// if the event loop got an event for a token associated with the session,
32    /// it will call this method
33    fn update_readiness(&mut self, token: Token, events: Ready);
34    /// close the state
35    fn close(&mut self, _proxy: Rc<RefCell<dyn L7Proxy>>, _metrics: &mut SessionMetrics) {}
36    /// if a timeout associated with the session triggers, the event loop will
37    /// call this method with the timeout's token
38    fn timeout(&mut self, token: Token, metrics: &mut SessionMetrics) -> StateResult;
39    /// cancel frontend timeout (and backend timeout if present)
40    fn cancel_timeouts(&mut self);
41    /// display the session's internal state (for debugging purpose),
42    /// ```plain
43    /// <context> Session(<State name>):
44    ///     Frontend:
45    ///         - Token(...) Readiness(...)
46    ///     Backends:
47    ///         - Token(...) Readiness(...)
48    ///         - Token(...) Readiness(...)
49    /// ```
50    fn print_state(&self, context: &str);
51    /// tell the session it has to shut down if possible
52    ///
53    /// if the session handles HTTP requests, it will not close until the response
54    /// is completely sent back to the client
55    fn shutting_down(&mut self) -> SessionIsToBeClosed {
56        true
57    }
58}