Example #1
0
void test_nghttp2_hd_public_api(void) {
  nghttp2_hd_deflater *deflater;
  nghttp2_hd_inflater *inflater;
  nghttp2_nv nva[] = {MAKE_NV("alpha", "bravo"), MAKE_NV("charlie", "delta")};
  uint8_t buf[4096];
  size_t buflen;
  ssize_t blocklen;
  nghttp2_bufs bufs;
  nghttp2_mem *mem;

  mem = nghttp2_mem_default();

  CU_ASSERT(0 == nghttp2_hd_deflate_new(&deflater, 4096));
  CU_ASSERT(0 == nghttp2_hd_inflate_new(&inflater));

  buflen = nghttp2_hd_deflate_bound(deflater, nva, ARRLEN(nva));

  blocklen = nghttp2_hd_deflate_hd(deflater, buf, buflen, nva, ARRLEN(nva));

  CU_ASSERT(blocklen > 0);

  nghttp2_bufs_wrap_init(&bufs, buf, blocklen, mem);
  bufs.head->buf.last += blocklen;

  CU_ASSERT(blocklen == inflate_hd(inflater, NULL, &bufs, 0, mem));

  nghttp2_bufs_wrap_free(&bufs);

  nghttp2_hd_inflate_del(inflater);
  nghttp2_hd_deflate_del(deflater);

  /* See NGHTTP2_ERR_INSUFF_BUFSIZE */
  CU_ASSERT(0 == nghttp2_hd_deflate_new(&deflater, 4096));

  blocklen =
      nghttp2_hd_deflate_hd(deflater, buf, blocklen - 1, nva, ARRLEN(nva));

  CU_ASSERT(NGHTTP2_ERR_INSUFF_BUFSIZE == blocklen);

  nghttp2_hd_deflate_del(deflater);
}
Example #2
0
  nghttp2_hd_deflater *deflater;
  nghttp2_hd_inflater *inflater;
  /* Define 1st header set.  This is looks like a HTTP request. */
  nghttp2_nv nva1[] = {
      MAKE_NV(":scheme", "https"), MAKE_NV(":authority", "example.org"),
      MAKE_NV(":path", "/"), MAKE_NV("user-agent", "libnghttp2"),
      MAKE_NV("accept-encoding", "gzip, deflate")};
  /* Define 2nd header set */
  nghttp2_nv nva2[] = {MAKE_NV(":scheme", "https"),
                       MAKE_NV(":authority", "example.org"),
                       MAKE_NV(":path", "/stylesheet/style.css"),
                       MAKE_NV("user-agent", "libnghttp2"),
                       MAKE_NV("accept-encoding", "gzip, deflate"),
                       MAKE_NV("referer", "https://example.org")};

  rv = nghttp2_hd_deflate_new(&deflater, 4096);

  if (rv != 0) {
    fprintf(stderr, "nghttp2_hd_deflate_init failed with error: %s\n",
            nghttp2_strerror(rv));
    exit(EXIT_FAILURE);
  }

  rv = nghttp2_hd_inflate_new(&inflater);

  if (rv != 0) {
    fprintf(stderr, "nghttp2_hd_inflate_init failed with error: %s\n",
            nghttp2_strerror(rv));
    exit(EXIT_FAILURE);
  }