Skip to main content

matier_core/
ext.rs

1//! Per-request / per-response `http::Extensions` types.
2
3use std::time::Duration;
4
5use crate::origin::Protocol;
6
7/// Deadline for receiving the response head.
8#[derive(Clone, Copy, Debug, PartialEq, Eq)]
9pub struct ResponseTimeout(pub Duration);
10
11/// Idle timeout between body chunks.
12#[derive(Clone, Copy, Debug, PartialEq, Eq)]
13pub struct BodyTimeout(pub Duration);
14
15/// RFC 9218 priority. Defaults: urgency 3, non-incremental.
16#[derive(Clone, Copy, Debug, PartialEq, Eq)]
17pub struct Priority {
18    /// 0 (highest) ..= 7 (lowest).
19    pub urgency: u8,
20    pub incremental: bool,
21}
22
23impl Default for Priority {
24    fn default() -> Self {
25        Self {
26            urgency: 3,
27            incremental: false,
28        }
29    }
30}
31
32impl Priority {
33    /// Creates a priority, clamping urgency to 0..=7.
34    #[must_use]
35    pub fn new(urgency: u8, incremental: bool) -> Self {
36        Self {
37            urgency: urgency.min(7),
38            incremental,
39        }
40    }
41}
42
43/// Low-cardinality URI template for telemetry (`url.template`).
44#[derive(Clone, Copy, Debug, PartialEq, Eq)]
45pub struct UriTemplate(pub &'static str);
46
47/// Response-side extension describing the connection that served the request.
48#[derive(Clone, Copy, Debug, PartialEq, Eq)]
49pub struct ConnectionInfo {
50    pub protocol: Protocol,
51    pub reused: bool,
52    pub conn_id: u64,
53}