Skip to main content

qubit_redact/formats/http/
http_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
10use std::sync::Arc;
11
12use super::TextBodyPolicy;
13use super::UrlPathPolicy;
14use super::internal::HttpPolicyParts;
15use crate::RedactionRules;
16
17/// Combines HTTP field rules and rendering choices.
18///
19/// Resource limits belong to the enclosing [`crate::RedactionPolicy`].
20///
21/// # Examples
22///
23/// ```
24/// use qubit_redact::RedactionPolicy;
25/// use qubit_redact::formats::http::UrlPathPolicy;
26///
27/// let policy = RedactionPolicy::standard();
28/// assert_eq!(policy.http().url_path_policy(), UrlPathPolicy::Preserve);
29/// ```
30#[derive(Debug, Clone, PartialEq, Eq)]
31pub struct HttpPolicy {
32    /// Shared immutable context policies behind cheap policy clones.
33    inner: Arc<HttpPolicyParts>,
34}
35
36impl HttpPolicy {
37    /// Creates an HTTP policy from its validated component policies.
38    ///
39    /// # Parameters
40    ///
41    /// * `parts` - Validated context rules and rendering choices to own.
42    ///
43    /// # Returns
44    ///
45    /// An immutable snapshot whose clones share the same Arc payload.
46    #[must_use]
47    #[inline(always)]
48    pub(super) fn from_parts(parts: HttpPolicyParts) -> Self {
49        Self { inner: Arc::new(parts) }
50    }
51
52    /// Returns the header field-rule snapshot.
53    ///
54    /// # Returns
55    ///
56    /// Borrowed classification rules for HTTP header names.
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    ///
65    /// # Returns
66    ///
67    /// Borrowed classification rules shared by query and form fields.
68    #[must_use]
69    #[inline(always)]
70    pub fn query_rules(&self) -> &RedactionRules {
71        &self.inner.query_rules
72    }
73
74    /// Returns the structured-body field-rule snapshot.
75    ///
76    /// # Returns
77    ///
78    /// Borrowed classification rules for structured body fields.
79    #[must_use]
80    #[inline(always)]
81    pub fn body_rules(&self) -> &RedactionRules {
82        &self.inner.body_rules
83    }
84
85    /// Returns the URL path visibility choice.
86    ///
87    /// # Returns
88    ///
89    /// The immutable URL-path visibility policy.
90    #[must_use]
91    #[inline(always)]
92    pub fn url_path_policy(&self) -> UrlPathPolicy {
93        self.inner.url_path_policy
94    }
95
96    /// Returns the opaque text-body visibility choice.
97    ///
98    /// # Returns
99    ///
100    /// The immutable visibility policy for opaque text bodies.
101    #[must_use]
102    #[inline(always)]
103    pub fn text_body_policy(&self) -> TextBodyPolicy {
104        self.inner.text_body_policy
105    }
106}