summaryrefslogtreecommitdiffstats
path: root/third_party/rust/headers/src/disabled/preference_applied.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/headers/src/disabled/preference_applied.rs
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/headers/src/disabled/preference_applied.rs')
-rw-r--r--third_party/rust/headers/src/disabled/preference_applied.rs110
1 files changed, 110 insertions, 0 deletions
diff --git a/third_party/rust/headers/src/disabled/preference_applied.rs b/third_party/rust/headers/src/disabled/preference_applied.rs
new file mode 100644
index 0000000000..b368bc9bb9
--- /dev/null
+++ b/third_party/rust/headers/src/disabled/preference_applied.rs
@@ -0,0 +1,110 @@
+use std::fmt;
+use {Header, Raw, Preference};
+use parsing::{from_comma_delimited, fmt_comma_delimited};
+
+/// `Preference-Applied` header, defined in [RFC7240](http://tools.ietf.org/html/rfc7240)
+///
+/// The `Preference-Applied` response header may be included within a
+/// response message as an indication as to which `Prefer` header tokens were
+/// honored by the server and applied to the processing of a request.
+///
+/// # ABNF
+///
+/// ```text
+/// Preference-Applied = "Preference-Applied" ":" 1#applied-pref
+/// applied-pref = token [ BWS "=" BWS word ]
+/// ```
+///
+/// # Example values
+///
+/// * `respond-async`
+/// * `return=minimal`
+/// * `wait=30`
+///
+/// # Examples
+///
+/// ```
+/// use headers::{Headers, PreferenceApplied, Preference};
+///
+/// let mut headers = Headers::new();
+/// headers.set(
+/// PreferenceApplied(vec![Preference::RespondAsync])
+/// );
+/// ```
+///
+/// ```
+/// use headers::{Headers, PreferenceApplied, Preference};
+///
+/// let mut headers = Headers::new();
+/// headers.set(
+/// PreferenceApplied(vec![
+/// Preference::RespondAsync,
+/// Preference::ReturnRepresentation,
+/// Preference::Wait(10u32),
+/// Preference::Extension("foo".to_owned(),
+/// "bar".to_owned(),
+/// vec![]),
+/// ])
+/// );
+/// ```
+#[derive(PartialEq, Clone, Debug)]
+pub struct PreferenceApplied(pub Vec<Preference>);
+
+__hyper__deref!(PreferenceApplied => Vec<Preference>);
+
+impl Header for PreferenceApplied {
+ fn header_name() -> &'static str {
+ static NAME: &'static str = "Preference-Applied";
+ NAME
+ }
+
+ fn parse_header(raw: &Raw) -> ::Result<PreferenceApplied> {
+ let preferences = try!(from_comma_delimited(raw));
+ if !preferences.is_empty() {
+ Ok(PreferenceApplied(preferences))
+ } else {
+ Err(::Error::Header)
+ }
+ }
+
+ fn fmt_header(&self, f: &mut ::Formatter) -> fmt::Result {
+ f.fmt_line(self)
+ }
+}
+
+impl fmt::Display for PreferenceApplied {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ //TODO: format this without allocating a Vec and cloning contents
+ let preferences: Vec<_> = self.0.iter().map(|pref| match pref {
+ // The spec ignores parameters in `Preferences-Applied`
+ &Preference::Extension(ref name, ref value, _) => Preference::Extension(
+ name.to_owned(),
+ value.to_owned(),
+ vec![]
+ ),
+ preference => preference.clone()
+ }).collect();
+ fmt_comma_delimited(f, &preferences)
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use Preference;
+ use super::*;
+
+ #[test]
+ fn test_format_ignore_parameters() {
+ assert_eq!(
+ format!("{}", PreferenceApplied(vec![Preference::Extension(
+ "foo".to_owned(),
+ "bar".to_owned(),
+ vec![("bar".to_owned(), "foo".to_owned()), ("buz".to_owned(), "".to_owned())]
+ )])),
+ "foo=bar".to_owned()
+ );
+ }
+}
+
+bench_header!(normal,
+ PreferenceApplied, { vec![b"respond-async, return=representation".to_vec(), b"wait=100".to_vec()] });