Example #1
0
static int32_t submit_headers_shared_nva(nghttp2_session *session,
                                         uint8_t flags, int32_t stream_id,
                                         const nghttp2_priority_spec *pri_spec,
                                         const nghttp2_nv *nva, size_t nvlen,
                                         const nghttp2_data_provider *data_prd,
                                         void *stream_user_data) {
  int rv;
  nghttp2_nv *nva_copy;
  nghttp2_priority_spec copy_pri_spec;
  nghttp2_mem *mem;

  mem = &session->mem;

  if (pri_spec) {
    copy_pri_spec = *pri_spec;
    nghttp2_priority_spec_normalize_weight(&copy_pri_spec);
  } else {
    nghttp2_priority_spec_default_init(&copy_pri_spec);
  }

  rv = nghttp2_nv_array_copy(&nva_copy, nva, nvlen, mem);
  if (rv < 0) {
    return rv;
  }

  return submit_headers_shared(session, flags, stream_id, &copy_pri_spec,
                               nva_copy, nvlen, data_prd, stream_user_data);
}
Example #2
0
void test_nghttp2_frame_pack_headers()
{
  nghttp2_hd_deflater deflater;
  nghttp2_hd_inflater inflater;
  nghttp2_headers frame, oframe;
  nghttp2_bufs bufs;
  nghttp2_nv *nva;
  nghttp2_priority_spec pri_spec;
  ssize_t nvlen;
  nva_out out;
  ssize_t hdblocklen;
  int rv;

  frame_pack_bufs_init(&bufs);

  nva_out_init(&out);
  nghttp2_hd_deflate_init(&deflater);
  nghttp2_hd_inflate_init(&inflater);

  nva = headers();
  nvlen = HEADERS_LENGTH;

  nghttp2_priority_spec_default_init(&pri_spec);

  nghttp2_frame_headers_init(&frame,
                             NGHTTP2_FLAG_END_STREAM |
                             NGHTTP2_FLAG_END_HEADERS,
                             1000000007, NGHTTP2_HCAT_REQUEST,
                             &pri_spec, nva, nvlen);
  rv = nghttp2_frame_pack_headers(&bufs, &frame, &deflater);

  nghttp2_bufs_rewind(&bufs);

  CU_ASSERT(0 == rv);
  CU_ASSERT(nghttp2_bufs_len(&bufs) > 0);
  CU_ASSERT(0 == unpack_framebuf((nghttp2_frame*)&oframe, &bufs));

  check_frame_header(nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN,
                     NGHTTP2_HEADERS,
                     NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS,
                     1000000007, &oframe.hd);
  /* We did not include PRIORITY flag */
  CU_ASSERT(NGHTTP2_DEFAULT_WEIGHT == oframe.pri_spec.weight);

  hdblocklen = nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN;
  CU_ASSERT(hdblocklen ==
            inflate_hd(&inflater, &out, &bufs, NGHTTP2_FRAME_HDLEN));

  CU_ASSERT(7 == out.nvlen);
  CU_ASSERT(nvnameeq("method", &out.nva[0]));
  CU_ASSERT(nvvalueeq("GET", &out.nva[0]));

  nghttp2_frame_headers_free(&oframe);
  nva_out_reset(&out);
  nghttp2_bufs_reset(&bufs);

  memset(&oframe, 0, sizeof(oframe));
  /* Next, include NGHTTP2_FLAG_PRIORITY */
  nghttp2_priority_spec_init(&frame.pri_spec, 1000000009, 12, 1);
  frame.hd.flags |= NGHTTP2_FLAG_PRIORITY;

  rv = nghttp2_frame_pack_headers(&bufs, &frame, &deflater);

  CU_ASSERT(0 == rv);
  CU_ASSERT(nghttp2_bufs_len(&bufs) > 0);
  CU_ASSERT(0 == unpack_framebuf((nghttp2_frame*)&oframe, &bufs));

  check_frame_header(nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN,
                     NGHTTP2_HEADERS,
                     NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS |
                     NGHTTP2_FLAG_PRIORITY,
                     1000000007, &oframe.hd);

  CU_ASSERT(1000000009 == oframe.pri_spec.stream_id);
  CU_ASSERT(12 == oframe.pri_spec.weight);
  CU_ASSERT(1 == oframe.pri_spec.exclusive);

  hdblocklen = nghttp2_bufs_len(&bufs) - NGHTTP2_FRAME_HDLEN
    - nghttp2_frame_priority_len(oframe.hd.flags);
  CU_ASSERT(hdblocklen ==
            inflate_hd(&inflater, &out, &bufs, NGHTTP2_FRAME_HDLEN
                       + nghttp2_frame_priority_len(oframe.hd.flags)));

  nghttp2_nv_array_sort(out.nva, out.nvlen);
  CU_ASSERT(nvnameeq("method", &out.nva[0]));

  nghttp2_frame_headers_free(&oframe);
  nva_out_reset(&out);
  nghttp2_bufs_reset(&bufs);

  nghttp2_bufs_free(&bufs);
  nghttp2_frame_headers_free(&frame);
  nghttp2_hd_inflate_free(&inflater);
  nghttp2_hd_deflate_free(&deflater);
}