Handle staic metatada string

pull/6029/head
yang-g 9 years ago
parent a863b8e4ef
commit 24ba7c12e2
  1. 19
      src/core/lib/transport/metadata.c
  2. 5
      test/core/transport/metadata_test.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;
}

@ -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();
}

Loading…
Cancel
Save