Skip to main content

h2session/
http_types.rs

1//! Generic HTTP request/response types
2//!
3//! These types represent parsed HTTP messages independent of the HTTP version.
4//! They can be used for both HTTP/1.x and HTTP/2 messages.
5
6use http::{HeaderMap, Method, StatusCode, Uri};
7
8use crate::state::TimestampNs;
9
10/// HTTP request parsed from any HTTP version
11#[derive(Debug, Clone)]
12pub struct HttpRequest {
13    /// HTTP method (GET, POST, etc.)
14    pub method:       Method,
15    /// Request target URI
16    pub uri:          Uri,
17    /// HTTP headers
18    pub headers:      HeaderMap,
19    /// Request body bytes
20    pub body:         Vec<u8>,
21    /// When this request was observed (nanosecond monotonic timestamp)
22    pub timestamp_ns: TimestampNs,
23    /// HTTP version: None for HTTP/2, Some(0) for HTTP/1.0, Some(1) for
24    /// HTTP/1.1
25    pub version:      Option<u8>,
26}
27
28/// HTTP response parsed from any HTTP version
29#[derive(Debug, Clone)]
30pub struct HttpResponse {
31    /// HTTP status code (200, 404, etc.)
32    pub status:       StatusCode,
33    /// HTTP headers
34    pub headers:      HeaderMap,
35    /// Response body bytes
36    pub body:         Vec<u8>,
37    /// When this response was observed (nanosecond monotonic timestamp)
38    pub timestamp_ns: TimestampNs,
39    /// HTTP version: None for HTTP/2, Some(0) for HTTP/1.0, Some(1) for
40    /// HTTP/1.1
41    pub version:      Option<u8>,
42    /// Reason phrase: None for HTTP/2, Some("OK") etc for HTTP/1
43    pub reason:       Option<String>,
44}