Skip to main content

tower_helmet/header/
x_dns_prefetch_control.rs

1use http::header::{HeaderName, InvalidHeaderValue};
2use http::HeaderValue;
3
4use crate::IntoHeader;
5
6/// `XDnsPrefetchControl` sets the `X-DNS-Prefetch-Control` header to help control DNS prefetching,
7/// which can improve user privacy at the expense of performance. See [documentation on MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-DNS-Prefetch-Control) for more.
8#[derive(Debug, Clone, Copy, Default)]
9pub struct XDnsPrefetchControl(
10    /// Is indictating whether to enable DNS prefetching.
11    pub bool,
12);
13
14impl IntoHeader for XDnsPrefetchControl {
15    fn header_name(&self) -> HeaderName {
16        http::header::X_DNS_PREFETCH_CONTROL
17    }
18
19    fn header_value(&self) -> Result<HeaderValue, InvalidHeaderValue> {
20        HeaderValue::from_str(if self.0 { "on" } else { "off" })
21    }
22}