aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2015-08-13 11:55:24 +0900
committerKazuki Yamaguchi <k@rhe.jp>2015-08-13 11:55:24 +0900
commitc1e0672e58a621b16ef34c22b2f603dc5d193968 (patch)
tree09434ff78fd5322eeb8b50f0b269291da18aefd1
parentc8551ca9b98110322d48fb536b3fdcc65bcd423b (diff)
downloadplum-c1e0672e58a621b16ef34c22b2f603dc5d193968.tar.gz
hpack: context: fix searching dynamic table
-rw-r--r--lib/plum/hpack/context.rb14
-rw-r--r--test/plum/hpack/test_context.rb20
2 files changed, 27 insertions, 7 deletions
diff --git a/lib/plum/hpack/context.rb b/lib/plum/hpack/context.rb
index 5973d94..71f07cb 100644
--- a/lib/plum/hpack/context.rb
+++ b/lib/plum/hpack/context.rb
@@ -34,12 +34,14 @@ module Plum
end
def search(name, value)
- if value
- i = STATIC_TABLE.index([name, value]) || @dynamic_table.index([name, value])
- else
- i = STATIC_TABLE.index {|n, _| n == name } || @dynamic_table.index {|n, _| n == name }
- end
- i && (i + 1) # index is >= 1
+ pr = proc {|n, v|
+ n == name && (!value || v == value)
+ }
+
+ si = STATIC_TABLE.index &pr
+ return si + 1 if si
+ di = @dynamic_table.index &pr
+ return di + STATIC_TABLE.size + 1 if di
end
def evict
diff --git a/test/plum/hpack/test_context.rb b/test/plum/hpack/test_context.rb
index cb92361..86654ec 100644
--- a/test/plum/hpack/test_context.rb
+++ b/test/plum/hpack/test_context.rb
@@ -34,11 +34,29 @@ class HPACKContextTest < Minitest::Test
}
end
+ def test_search_static
+ context = new_context
+ i1 = context.search(":method", "POST")
+ assert_equal(3, i1)
+ end
+
+ def test_search_dynamic
+ context = new_context
+ context.store("あああ", "abc")
+ context.store("あああ", "いい")
+ i1 = context.search("あああ", "abc")
+ assert_equal(63, i1)
+ i2 = context.search("あああ", "AAA")
+ assert_equal(nil, i2)
+ i3 = context.search("あああ", nil)
+ assert_equal(62, i3)
+ end
+
private
def new_context(limit = 1 << 31)
@c ||= Class.new {
include Plum::HPACK::Context
- public :initialize, :store, :fetch, :evict
+ public *Plum::HPACK::Context.private_instance_methods
}
@c.new(limit)
end