Skip to main content

qubit_redact/http/
http_redaction_policy.rs

1// =============================================================================
2//    Copyright (c) 2025 - 2026 Haixing Hu.
3//
4//    SPDX-License-Identifier: Apache-2.0
5//
6//    Licensed under the Apache License, Version 2.0.
7// =============================================================================
8//! Immutable policy snapshot for every HTTP redaction context.
9// qubit-style: allow type-file-name
10
11use std::sync::Arc;
12
13use crate::RedactionRules;
14
15use super::http_redaction_policy_parts::HttpPolicyParts;
16use super::{
17    TextBodyPolicy,
18    UrlPathPolicy,
19};
20
21/// Combines HTTP field rules, behavior choices, and resource limits.
22#[must_use]
23#[derive(Debug, Clone, PartialEq, Eq)]
24pub struct HttpPolicy {
25    inner: Arc<HttpPolicyInner>,
26}
27
28/// Shared immutable HTTP behavior state.
29#[derive(Debug, Clone, PartialEq, Eq)]
30struct HttpPolicyInner {
31    header_rules: RedactionRules,
32    query_rules: RedactionRules,
33    body_rules: RedactionRules,
34    url_path_policy: UrlPathPolicy,
35    text_body_policy: TextBodyPolicy,
36}
37
38impl HttpPolicy {
39    pub(super) fn from_parts(parts: HttpPolicyParts) -> Self {
40        Self {
41            inner: std::sync::Arc::new(HttpPolicyInner {
42                header_rules: parts.header_rules,
43                query_rules: parts.query_rules,
44                body_rules: parts.body_rules,
45                url_path_policy: parts.url_path_policy,
46                text_body_policy: parts.text_body_policy,
47            }),
48        }
49    }
50
51    /// Returns the header field-rule snapshot.
52    #[inline(always)]
53    pub fn header_rules(&self) -> &RedactionRules {
54        &self.inner.header_rules
55    }
56
57    /// Returns the query and form field-rule snapshot.
58    #[inline(always)]
59    pub fn query_rules(&self) -> &RedactionRules {
60        &self.inner.query_rules
61    }
62
63    /// Returns the structured-body field-rule snapshot.
64    #[inline(always)]
65    pub fn body_rules(&self) -> &RedactionRules {
66        &self.inner.body_rules
67    }
68
69    /// Returns the URL path visibility choice.
70    #[inline(always)]
71    pub fn url_path_policy(&self) -> UrlPathPolicy {
72        self.inner.url_path_policy
73    }
74
75    /// Returns the opaque text-body visibility choice.
76    #[inline(always)]
77    pub fn text_body_policy(&self) -> TextBodyPolicy {
78        self.inner.text_body_policy
79    }
80}