summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2015-08-12 22:10:44 +0900
committerKazuki Yamaguchi <k@rhe.jp>2015-08-12 22:10:44 +0900
commita429578603c30eb205136b00b90cf0ac640f9173 (patch)
tree004b06b187543715cab97b560272ab930ec69f84
parentad4eadf1099f6ac606134d50a5abd420a53f2dfa (diff)
downloadplum-a429578603c30eb205136b00b90cf0ac640f9173.tar.gz
hpack: decoder: refactor
-rw-r--r--lib/plum/hpack/context.rb10
-rw-r--r--lib/plum/hpack/decoder.rb6
2 files changed, 10 insertions, 6 deletions
diff --git a/lib/plum/hpack/context.rb b/lib/plum/hpack/context.rb
index 0a4f6c2..0d0eb63 100644
--- a/lib/plum/hpack/context.rb
+++ b/lib/plum/hpack/context.rb
@@ -22,7 +22,15 @@ module Plum
end
def fetch(index)
- STATIC_TABLE[index - 1] || @dynamic_table[index - STATIC_TABLE.size - 1] or raise HPACKError.new("invalid index: #{index}")
+ if index == 0
+ raise HPACKError.new("index can't be 0")
+ elsif index <= STATIC_TABLE.size
+ STATIC_TABLE[index - 1]
+ elsif index <= STATIC_TABLE.size + @dynamic_table.size
+ @dynamic_table[index - STATIC_TABLE.size - 1]
+ else
+ raise HPACKError.new("invalid index: #{index}")
+ end
end
def evict
diff --git a/lib/plum/hpack/decoder.rb b/lib/plum/hpack/decoder.rb
index c298a0c..adc34e5 100644
--- a/lib/plum/hpack/decoder.rb
+++ b/lib/plum/hpack/decoder.rb
@@ -60,11 +60,7 @@ module Plum
# | 1 | Index (7+) |
# +---+---------------------------+
index = read_integer!(str, 7)
- if index == 0
- raise HPACKError.new("index can't be 0 in indexed heaeder field representation")
- else
- fetch(index)
- end
+ fetch(index)
end
def parse_indexing!(str)