Repository: trafficserver
Updated Branches:
  refs/heads/master 97f4ef08b -> 5115a6fd5


TS-4018: Use HPACK huffman encoding always

This closes #362


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/5115a6fd
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/5115a6fd
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/5115a6fd

Branch: refs/heads/master
Commit: 5115a6fd569893428890c925267c8dd0dba848ac
Parents: 97f4ef0
Author: Masakazu Kitajo <[email protected]>
Authored: Mon Dec 7 17:27:39 2015 -0800
Committer: Bryan Call <[email protected]>
Committed: Mon Dec 7 17:30:55 2015 -0800

----------------------------------------------------------------------
 proxy/http2/HPACK.cc | 33 ++++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/5115a6fd/proxy/http2/HPACK.cc
----------------------------------------------------------------------
diff --git a/proxy/http2/HPACK.cc b/proxy/http2/HPACK.cc
index 6421a37..b05f3a8 100644
--- a/proxy/http2/HPACK.cc
+++ b/proxy/http2/HPACK.cc
@@ -332,18 +332,41 @@ int64_t
 encode_string(uint8_t *buf_start, const uint8_t *buf_end, const char *value, 
size_t value_len)
 {
   uint8_t *p = buf_start;
+  bool use_huffman = true;
+  char *data = NULL;
+  int64_t data_len = 0;
+
+  // TODO Choose whether to use Huffman encoding wisely
+
+  if (use_huffman) {
+    data = static_cast<char *>(ats_malloc(value_len * 4));
+    if (data == NULL)
+      return -1;
+    data_len = huffman_encode(reinterpret_cast<uint8_t *>(data), 
reinterpret_cast<const uint8_t *>(value), value_len);
+  } else {
+    data = const_cast<char *>(value);
+    data_len = value_len;
+  }
 
   // Length
-  const int64_t len = encode_integer(p, buf_end, value_len, 7);
+  const int64_t len = encode_integer(p, buf_end, data_len, 7);
   if (len == -1)
     return -1;
+  if (use_huffman) {
+    *p |= 0x80;
+  }
   p += len;
-  if (buf_end < p || static_cast<size_t>(buf_end - p) < value_len)
+  if (buf_end < p || buf_end - p < data_len)
     return -1;
 
-  // Value String
-  memcpy(p, value, value_len);
-  p += value_len;
+  // Value
+  memcpy(p, data, data_len);
+  p += data_len;
+
+  if (use_huffman) {
+    ats_free(data);
+  }
+
   return p - buf_start;
 }
 

Reply via email to