aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2015-08-14 18:31:21 +0900
committerKazuki Yamaguchi <k@rhe.jp>2015-08-14 18:31:21 +0900
commita80d386e915315e1d789c9171ccd725efc36503b (patch)
tree0bee298c1d8013171429a2894b4221db1703d9bf /lib
parent771d444bb5ddd3d49dfec874fd6ac1288bd9b9b3 (diff)
downloadplum-a80d386e915315e1d789c9171ccd725efc36503b.tar.gz
hpack: update test cases
Diffstat (limited to 'lib')
-rw-r--r--lib/plum/hpack/encoder.rb25
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/plum/hpack/encoder.rb b/lib/plum/hpack/encoder.rb
index a1a09e8..2dc2482 100644
--- a/lib/plum/hpack/encoder.rb
+++ b/lib/plum/hpack/encoder.rb
@@ -5,9 +5,10 @@ module Plum
class Encoder
include HPACK::Context
- def initialize(dynamic_table_limit, indexing: true)
+ def initialize(dynamic_table_limit, indexing: true, huffman: true)
super(dynamic_table_limit)
@indexing = indexing
+ @huffman = huffman
end
def encode(headers)
@@ -94,15 +95,25 @@ module Plum
end
def encode_string(str)
- huffman_str = Huffman.encode(str)
- if huffman_str.bytesize < str.bytesize
- lenstr = encode_integer(huffman_str.bytesize, 7)
- lenstr.setbyte(0, lenstr.uint8(0) | 0b10000000)
- lenstr.force_encoding(Encoding::BINARY) << huffman_str
+ if @huffman
+ hs = encode_string_huffman(str)
+ ps = encode_string_plain(str)
+ hs.bytesize < ps.bytesize ? hs : ps
else
- encode_integer(str.bytesize, 7) << str.force_encoding(Encoding::BINARY)
+ encode_string_plain(str)
end
end
+
+ def encode_string_plain(str)
+ encode_integer(str.bytesize, 7) << str.force_encoding(Encoding::BINARY)
+ end
+
+ def encode_string_huffman(str)
+ huffman_str = Huffman.encode(str)
+ lenstr = encode_integer(huffman_str.bytesize, 7)
+ lenstr.setbyte(0, lenstr.uint8(0) | 0b10000000)
+ lenstr.force_encoding(Encoding::BINARY) << huffman_str
+ end
end
end
end