Skip to main content

gproxy_protocol/connection/
mod.rs

1//! HTTP messages, body representations, and independent WebSocket connections.
2//!
3//! HTTP metadata stays outside the body even when the body has been decoded
4//! into a vendor's JSON type. Multipart and event streams are HTTP bodies.
5//! A WebSocket handshake uses HTTP; the established socket has its own duplex
6//! interface and is never an HTTP body variant.
7
8mod body;
9mod websocket;
10
11pub use body::{ByteStream, HttpBody, Multipart, MultipartPart, PartStream, StreamFraming};
12pub use websocket::{WebSocket, WsClose, WsFrame, WsReceiver, WsSender};
13
14pub use bytes::Bytes;
15pub use http::{HeaderMap, HeaderName, HeaderValue, Method, StatusCode};
16
17/// An error supplied by the transport adapter while receiving or sending data.
18pub type TransportError = Box<dyn std::error::Error + Send + Sync + 'static>;
19
20/// An HTTP request with five elements.
21///
22/// `path` and `query` retain their original percent encoding. `query` excludes
23/// the leading `?`; `None` and `Some("")` distinguish an absent and empty query.
24/// Repeated parameters and their order are preserved. The transport adapter
25/// supplies the destination host independently.
26///
27/// `B` can be raw [`HttpBody`], a decoded JSON body, or parsed [`Multipart`].
28/// GET operations use `()` for an absent body, not a JSON `null` body.
29#[derive(Debug)]
30pub struct WireRequest<B = HttpBody> {
31    pub method: Method,
32    pub path: String,
33    pub query: Option<String>,
34    pub headers: HeaderMap,
35    pub body: B,
36}
37
38/// An HTTP response with three elements, independent of the body representation.
39#[derive(Debug)]
40pub struct WireResponse<B = HttpBody> {
41    pub status: StatusCode,
42    pub headers: HeaderMap,
43    pub body: B,
44}