/// Constructs a priority from raw bytes (either a field value of frame content). /// /// # Errors /// /// When the contained syntax is invalid. pubfn from_bytes(bytes: &[u8]) -> Res<Self> { #[cfg(feature = "build-fuzzing-corpus")]
neqo_common::write_item_to_fuzzing_corpus("priority", bytes);
let dict: Dictionary = Parser::new(bytes).parse().map_err(|_| Error::HttpFrame)?; let urgency = match dict.get("u") {
Some(ListEntry::Item(Item {
bare_item: BareItem::Integer(u),
..
})) if (Integer::constant(0)..=Integer::constant(7)).contains(u) => {
u8::try_from(*u).map_err(|_| Error::Internal)?
}
_ => 3,
}; let incremental = match dict.get("i") {
Some(ListEntry::Item(Item {
bare_item: BareItem::Boolean(i),
..
})) => *i,
_ => false,
};
Ok(Self {
urgency,
incremental,
})
}
}
#[test] fn priority_updates_ignore_same() { letmut p = PriorityHandler::new(false, Priority::new(5, false));
assert!(!p.maybe_update_priority(Priority::new(5, false))); // updating with the same priority -> there should not be any priority frame sent
assert!(p.maybe_encode_frame(StreamId::new(4)).is_none());
}
#[test] fn priority_updates_send_update() { letmut p = PriorityHandler::new(false, Priority::new(5, false));
assert!(p.maybe_update_priority(Priority::new(6, false))); // updating with the a different priority -> there should be a priority frame sent
assert!(p.maybe_encode_frame(StreamId::new(4)).is_some());
}
#[test] fn multiple_priority_updates_ignore_same() { letmut p = PriorityHandler::new(false, Priority::new(5, false));
assert!(p.maybe_update_priority(Priority::new(6, false)));
assert!(p.maybe_update_priority(Priority::new(5, false))); // initial and last priority same -> there should not be any priority frame sent
assert!(p.maybe_encode_frame(StreamId::new(4)).is_none());
}
#[test] fn multiple_priority_updates_send_update() { letmut p = PriorityHandler::new(false, Priority::new(5, false));
assert!(p.maybe_update_priority(Priority::new(6, false)));
assert!(p.maybe_update_priority(Priority::new(7, false))); // updating two times with a different priority -> the last priority update should be in the // next frame let expected = HFrame::PriorityUpdateRequest {
element_id: 4,
priority: Priority::new(7, false),
};
assert_eq!(p.maybe_encode_frame(StreamId::new(4)), Some(expected));
}
#[test] fn priority_updates_incremental() { letmut p = PriorityHandler::new(false, Priority::new(5, false));
assert!(p.maybe_update_priority(Priority::new(5, true))); // updating the incremental parameter -> there should be a priority frame sent let expected = HFrame::PriorityUpdateRequest {
element_id: 4,
priority: Priority::new(5, true),
};
assert_eq!(p.maybe_encode_frame(StreamId::new(4)), Some(expected));
}
#[test] fn priority_update_sent_clears_pending() { letmut p = PriorityHandler::new(false, Priority::new(5, false));
assert!(p.maybe_update_priority(Priority::new(6, false)));
assert!(p.maybe_encode_frame(StreamId::new(4)).is_some());
p.priority_update_sent(); // After sending, no more pending update.
assert!(p.maybe_encode_frame(StreamId::new(4)).is_none());
}
#[test] fn from_bytes_invalid_urgency_defaults() { // Urgency outside 0-7 should default to 3. let p = Priority::from_bytes(b"u=8").unwrap();
assert_eq!(p, Priority::default());
let p = Priority::from_bytes(b"u=-1").unwrap();
assert_eq!(p, Priority::default());
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.