You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ma...@apache.org on 2018/08/27 07:05:53 UTC
[trafficserver] 03/05: Preserve the prefix bits when encoding
integer with XPACK
This is an automated email from the ASF dual-hosted git repository.
maskit pushed a commit to branch quic-latest
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit e755cc8500624689612ceccc49ee7ff228b6f834
Author: Masakazu Kitajo <ma...@apache.org>
AuthorDate: Fri Jul 27 12:19:32 2018 +0900
Preserve the prefix bits when encoding integer with XPACK
---
proxy/hdrs/XPACK.cc | 9 +++++++++
proxy/hdrs/XPACK.h | 1 +
proxy/http2/HPACK.cc | 3 ++-
3 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/proxy/hdrs/XPACK.cc b/proxy/hdrs/XPACK.cc
index c537872..73d6e80 100644
--- a/proxy/hdrs/XPACK.cc
+++ b/proxy/hdrs/XPACK.cc
@@ -118,6 +118,9 @@ xpack_encode_integer(uint8_t *buf_start, const uint8_t *buf_end, uint64_t value,
uint8_t *p = buf_start;
+ // Preserve the first n bits
+ uint8_t prefix = *buf_start & (0xFF << n);
+
if (value < (static_cast<uint64_t>(1 << n) - 1)) {
*(p++) = value;
} else {
@@ -135,6 +138,10 @@ xpack_encode_integer(uint8_t *buf_start, const uint8_t *buf_end, uint64_t value,
}
*(p++) = value;
}
+
+ // Restore the prefix
+ *buf_start |= prefix;
+
return p - buf_start;
}
@@ -168,6 +175,8 @@ xpack_encode_string(uint8_t *buf_start, const uint8_t *buf_end, const char *valu
if (use_huffman) {
*p |= 0x01 << n;
+ } else {
+ *p &= ~(0x01 << n);
}
p += len;
diff --git a/proxy/hdrs/XPACK.h b/proxy/hdrs/XPACK.h
index 5e8eca3..bb3bc71 100644
--- a/proxy/hdrs/XPACK.h
+++ b/proxy/hdrs/XPACK.h
@@ -24,6 +24,7 @@
#pragma once
#include <cstdint>
+#include "ts/Arena.h"
const static int XPACK_ERROR_COMPRESSION_ERROR = -1;
const static int XPACK_ERROR_SIZE_EXCEEDED_ERROR = -2;
diff --git a/proxy/http2/HPACK.cc b/proxy/http2/HPACK.cc
index fd16460..f51f947 100644
--- a/proxy/http2/HPACK.cc
+++ b/proxy/http2/HPACK.cc
@@ -465,6 +465,7 @@ encode_literal_header_field_with_indexed_name(uint8_t *buf_start, const uint8_t
}
// Index
+ *p = 0;
len = xpack_encode_integer(p, buf_end, index, prefix);
if (len == -1) {
return -1;
@@ -553,11 +554,11 @@ encode_literal_header_field_with_new_name(uint8_t *buf_start, const uint8_t *buf
int64_t
encode_dynamic_table_size_update(uint8_t *buf_start, const uint8_t *buf_end, uint32_t size)
{
+ buf_start[0] = 0x20;
const int64_t len = xpack_encode_integer(buf_start, buf_end, size, 5);
if (len == -1) {
return -1;
}
- buf_start[0] |= 0x20;
return len;
}