From d7722274dd60c3aa9fed5259a7e33b2829838047 Mon Sep 17 00:00:00 2001 From: evolix1 Date: Thu, 9 Aug 2018 10:40:45 +0100 Subject: [PATCH] Fix static table index --- quinn-h3/src/qpack/table/static_.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/quinn-h3/src/qpack/table/static_.rs b/quinn-h3/src/qpack/table/static_.rs index 8b734e80b..2bede507d 100644 --- a/quinn-h3/src/qpack/table/static_.rs +++ b/quinn-h3/src/qpack/table/static_.rs @@ -88,7 +88,8 @@ pub struct StaticTable {} impl StaticTable { pub fn get(index: usize) -> Option<&'static HeaderField> { - PREDEFINED_HEADERS.get(index) + if index == 0 { None } + else { PREDEFINED_HEADERS.get(index - 1) } } pub fn count() -> usize { @@ -105,6 +106,17 @@ mod tests { fn test_static_table_is_available() { let field = HeaderField::new("www-authenticate", ""); assert_eq!(StaticTable::count(), 61); - assert_eq!(StaticTable::get(60), Some(&field)); + assert_eq!(StaticTable::get(61), Some(&field)); + } + + /** + * https://tools.ietf.org/html/draft-ietf-quic-qpack-01 + * 2.1. Static Table + * [...] Note that because HPACK did not use zero-based references, + * there is no value at index zero of the static table. + */ + #[test] + fn test_static_table_index_is_1_based() { + assert_eq!(StaticTable::get(0), None); } }