Skip to main content

qubit_redact/formats/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// qubit-style: allow multiple-public-types
11
12use std::sync::Arc;
13
14use super::TextBodyPolicy;
15use super::UrlPathPolicy;
16use super::http_redaction_policy_parts::HttpPolicyParts;
17use crate::RedactionRules;
18
19/// Combines HTTP field rules, behavior choices, and resource limits.
20#[derive(Debug, Clone, PartialEq, Eq)]
21pub struct HttpPolicy {
22    /// Shared immutable context policies behind cheap policy clones.
23    inner: Arc<HttpPolicyInner>,
24}
25
26/// Shared immutable HTTP behavior state.
27#[derive(Debug, Clone, PartialEq, Eq)]
28struct HttpPolicyInner {
29    /// Header-name classification snapshot.
30    header_rules: RedactionRules,
31    /// URL-query and form-field classification snapshot.
32    query_rules: RedactionRules,
33    /// Structured-body field classification snapshot.
34    body_rules: RedactionRules,
35    /// Visibility rule for URL path components.
36    url_path_policy: UrlPathPolicy,
37    /// Visibility rule for opaque UTF-8 bodies.
38    text_body_policy: TextBodyPolicy,
39}
40
41impl HttpPolicy {
42    /// Creates an HTTP policy from its validated component policies.
43    #[must_use]
44    pub(super) fn from_parts(parts: HttpPolicyParts) -> Self {
45        Self {
46            inner: std::sync::Arc::new(HttpPolicyInner {
47                header_rules: parts.header_rules,
48                query_rules: parts.query_rules,
49                body_rules: parts.body_rules,
50                url_path_policy: parts.url_path_policy,
51                text_body_policy: parts.text_body_policy,
52            }),
53        }
54    }
55
56    /// Returns the header field-rule snapshot.
57    #[must_use]
58    #[inline(always)]
59    pub fn header_rules(&self) -> &RedactionRules {
60        &self.inner.header_rules
61    }
62
63    /// Returns the query and form field-rule snapshot.
64    #[must_use]
65    #[inline(always)]
66    pub fn query_rules(&self) -> &RedactionRules {
67        &self.inner.query_rules
68    }
69
70    /// Returns the structured-body field-rule snapshot.
71    #[must_use]
72    #[inline(always)]
73    pub fn body_rules(&self) -> &RedactionRules {
74        &self.inner.body_rules
75    }
76
77    /// Returns the URL path visibility choice.
78    #[must_use]
79    #[inline(always)]
80    pub fn url_path_policy(&self) -> UrlPathPolicy {
81        self.inner.url_path_policy
82    }
83
84    /// Returns the opaque text-body visibility choice.
85    #[must_use]
86    #[inline(always)]
87    pub fn text_body_policy(&self) -> TextBodyPolicy {
88        self.inner.text_body_policy
89    }
90}