Exemple #1
0
static grpc_slice get_wire_value(grpc_mdelem elem, uint8_t *huffman_prefix) {
  if (grpc_is_binary_header(GRPC_MDKEY(elem))) {
    *huffman_prefix = 0x80;
    return grpc_chttp2_base64_encode_and_huffman_compress(GRPC_MDVALUE(elem));
  }
  /* TODO(ctiller): opportunistically compress non-binary headers */
  *huffman_prefix = 0x00;
  return grpc_slice_ref_internal(GRPC_MDVALUE(elem));
}
Exemple #2
0
gpr_slice grpc_mdstr_as_base64_encoded_and_huffman_compressed(grpc_mdstr *gs) {
  internal_string *s = (internal_string *)gs;
  gpr_slice slice;
  grpc_mdctx *ctx = s->context;
  lock(ctx);
  if (!s->has_base64_and_huffman_encoded) {
    s->base64_and_huffman =
        grpc_chttp2_base64_encode_and_huffman_compress(s->slice);
    s->has_base64_and_huffman_encoded = 1;
  }
  slice = s->base64_and_huffman;
  unlock(ctx);
  return slice;
}
Exemple #3
0
static void test_base64_and_huffman_works(void) {
  grpc_mdstr *str;
  gpr_slice slice1;
  gpr_slice slice2;

  LOG_TEST("test_base64_and_huffman_works");

  grpc_init();
  str = grpc_mdstr_from_string("abcdefg");
  slice1 = grpc_mdstr_as_base64_encoded_and_huffman_compressed(str);
  slice2 = grpc_chttp2_base64_encode_and_huffman_compress(str->slice);
  GPR_ASSERT(0 == gpr_slice_cmp(slice1, slice2));

  gpr_slice_unref(slice2);
  GRPC_MDSTR_UNREF(str);
  grpc_shutdown();
}
Exemple #4
0
static void expect_combined_equiv(const char *s, size_t len, int line) {
  gpr_slice input = gpr_slice_from_copied_buffer(s, len);
  gpr_slice base64 = grpc_chttp2_base64_encode(input);
  gpr_slice expect = grpc_chttp2_huffman_compress(base64);
  gpr_slice got = grpc_chttp2_base64_encode_and_huffman_compress(input);
  if (0 != gpr_slice_cmp(expect, got)) {
    char *t = gpr_hexdump((const char *)GPR_SLICE_START_PTR(input),
                          GPR_SLICE_LENGTH(input), GPR_HEXDUMP_PLAINTEXT);
    char *e = gpr_hexdump((const char *)GPR_SLICE_START_PTR(expect),
                          GPR_SLICE_LENGTH(expect), GPR_HEXDUMP_PLAINTEXT);
    char *g = gpr_hexdump((const char *)GPR_SLICE_START_PTR(got),
                          GPR_SLICE_LENGTH(got), GPR_HEXDUMP_PLAINTEXT);
    gpr_log(GPR_ERROR, "FAILED:%d:\ntest: %s\ngot:  %s\nwant: %s", t, g, e);
    gpr_free(t);
    gpr_free(e);
    gpr_free(g);
    all_ok = 0;
  }
  gpr_slice_unref(input);
  gpr_slice_unref(base64);
  gpr_slice_unref(expect);
  gpr_slice_unref(got);
}