diff options
author | yang-g <yangg@google.com> | 2016-03-30 16:19:43 -0700 |
---|---|---|
committer | yang-g <yangg@google.com> | 2016-03-30 16:19:43 -0700 |
commit | 24ba7c12e2e63345d28c9464d135f9efa82eef22 (patch) | |
tree | 9d383409c005bec83dd1990853a0b4417e5021f4 | |
parent | a863b8e4ef911c1d18808822f5524b891e7f486f (diff) |
Handle staic metatada string
-rw-r--r-- | src/core/lib/transport/metadata.c | 19 | ||||
-rw-r--r-- | test/core/transport/metadata_test.c | 5 |
2 files changed, 19 insertions, 5 deletions
diff --git a/src/core/lib/transport/metadata.c b/src/core/lib/transport/metadata.c index b1005f317a..a0c295275f 100644 --- a/src/core/lib/transport/metadata.c +++ b/src/core/lib/transport/metadata.c @@ -582,21 +582,30 @@ grpc_mdelem *grpc_mdelem_from_string_and_buffer(const char *key, grpc_mdstr_from_string(key), grpc_mdstr_from_buffer(value, value_length)); } +static size_t get_base64_encoded_size(size_t raw_length) { + static const uint8_t tail_xtra[3] = {0, 2, 3}; + return raw_length / 3 * 4 + tail_xtra[raw_length % 3]; +} + size_t grpc_mdelem_get_size_in_hpack_table(grpc_mdelem *elem) { size_t overhead_and_key = 32 + GPR_SLICE_LENGTH(elem->key->slice); + size_t value_len = GPR_SLICE_LENGTH(elem->value->slice); if (is_mdstr_static(elem->value)) { - return overhead_and_key + GPR_SLICE_LENGTH(elem->value->slice); + if (grpc_is_binary_header( + (const char *)GPR_SLICE_START_PTR(elem->key->slice), + GPR_SLICE_LENGTH(elem->key->slice))) { + return overhead_and_key + get_base64_encoded_size(value_len); + } else { + return overhead_and_key + value_len; + } } else { internal_string *is = (internal_string *)elem->value; - size_t value_len = GPR_SLICE_LENGTH(is->slice); - static const uint8_t tail_xtra[3] = {0, 2, 3}; if (is->has_size_in_decoder_table == 0) { is->has_size_in_decoder_table = 1; if (grpc_is_binary_header( (const char *)GPR_SLICE_START_PTR(elem->key->slice), GPR_SLICE_LENGTH(elem->key->slice))) { - is->size_in_decoder_table = - value_len / 3 * 4 + tail_xtra[value_len % 3]; + is->size_in_decoder_table = get_base64_encoded_size(value_len); } else { is->size_in_decoder_table = value_len; } diff --git a/test/core/transport/metadata_test.c b/test/core/transport/metadata_test.c index 6037f9b896..7787b32308 100644 --- a/test/core/transport/metadata_test.c +++ b/test/core/transport/metadata_test.c @@ -43,6 +43,7 @@ #include "src/core/ext/transport/chttp2/transport/bin_encoder.h" #include "src/core/lib/support/string.h" +#include "src/core/lib/transport/static_metadata.h" #include "test/core/util/test_config.h" #define LOG_TEST(x) gpr_log(GPR_INFO, "%s", x) @@ -302,6 +303,10 @@ static void test_mdelem_sizes_in_hpack(void) { verify_binary_header_size("hello-bin", binary_value, i); } + const char *static_metadata = grpc_static_metadata_strings[0]; + memcpy(binary_value, static_metadata, strlen(static_metadata)); + verify_binary_header_size("hello-bin", binary_value, strlen(static_metadata)); + grpc_shutdown(); } |