Integrate new header compression

This commit is contained in:
Tatsuhiro Tsujikawa
2013-07-20 00:08:14 +09:00
parent 45c2245bfb
commit 61bf7c6b02
22 changed files with 430 additions and 1098 deletions

View File

@@ -162,20 +162,6 @@ int main(int argc, char* argv[])
test_nghttp2_session_set_option) ||
!CU_add_test(pSuite, "session_data_backoff_by_high_pri_frame",
test_nghttp2_session_data_backoff_by_high_pri_frame) ||
!CU_add_test(pSuite, "frame_unpack_nv",
test_nghttp2_frame_unpack_nv) ||
!CU_add_test(pSuite, "frame_unpack_nv_check_name",
test_nghttp2_frame_unpack_nv_check_name) ||
!CU_add_test(pSuite, "frame_unpack_nv_last_empty_value",
test_nghttp2_frame_unpack_nv_last_empty_value) ||
!CU_add_test(pSuite, "frame_pack_nv_duplicate_keys",
test_nghttp2_frame_pack_nv_duplicate_keys) ||
!CU_add_test(pSuite, "frame_count_nv_space",
test_nghttp2_frame_count_nv_space) ||
!CU_add_test(pSuite, "frame_pack_nv_empty_value",
test_nghttp2_frame_pack_nv_empty_value) ||
!CU_add_test(pSuite, "frame_count_unpack_nv_space",
test_nghttp2_frame_count_unpack_nv_space) ||
!CU_add_test(pSuite, "frame_nv_sort", test_nghttp2_frame_nv_sort) ||
!CU_add_test(pSuite, "frame_nv_downcase",
test_nghttp2_frame_nv_downcase) ||

View File

@@ -33,13 +33,6 @@
#include "nghttp2_helper.h"
#include "nghttp2_test_helper.h"
/* Reads |len_size| byte from |data| as 2 bytes network byte
order integer, and returns it in host byte order. */
static int get_packed_hd_len(uint8_t *data, size_t len_size)
{
return nghttp2_get_uint16(data);
}
static const char *headers[] = {
"method", "GET",
"scheme", "https",
@@ -51,376 +44,6 @@ static const char *headers[] = {
NULL
};
void test_nghttp2_frame_unpack_nv()
{
size_t len_size = 2;
uint8_t out[1024];
char **nv;
size_t inlen = nghttp2_frame_pack_nv(out, (char**)headers, len_size);
nghttp2_buffer buffer;
nghttp2_buffer_init(&buffer, 4096);
nghttp2_buffer_write(&buffer, out, inlen);
CU_ASSERT(0 == nghttp2_frame_unpack_nv(&nv, &buffer, len_size));
CU_ASSERT(strcmp("method", nv[0]) == 0);
CU_ASSERT(strcmp("GET", nv[1]) == 0);
CU_ASSERT(strcmp("scheme", nv[2]) == 0);
CU_ASSERT(strcmp("https", nv[3]) == 0);
CU_ASSERT(strcmp("url", nv[4]) == 0);
CU_ASSERT(strcmp("/", nv[5]) == 0);
CU_ASSERT(strcmp("version", nv[6]) == 0);
CU_ASSERT(strcmp("HTTP/1.1", nv[7]) == 0);
CU_ASSERT(strcmp("x-empty", nv[8]) == 0);
CU_ASSERT(strcmp("", nv[9]) == 0);
CU_ASSERT(strcmp("x-head", nv[10]) == 0);
CU_ASSERT(strcmp("foo", nv[11]) == 0);
CU_ASSERT(strcmp("x-head", nv[12]) == 0);
CU_ASSERT(strcmp("bar", nv[13]) == 0);
nghttp2_frame_nv_del(nv);
/* Create in-sequence NUL bytes */
/* Assuming first chunk has enough space to store 1st name/value
pair. */
memcpy(&buffer.root.next->data[len_size +
len_size + strlen(headers[0]) +
len_size + strlen(headers[1])-2],
"\0\0", 2);
CU_ASSERT(NGHTTP2_ERR_INVALID_HEADER_BLOCK ==
nghttp2_frame_unpack_nv(&nv, &buffer, len_size));
nghttp2_frame_nv_del(nv);
nghttp2_buffer_free(&buffer);
}
/* This function intentionally does not merge same header field into
one */
static size_t nghttp2_pack_nv(uint8_t *buf, size_t buflen, const char **nv,
size_t len_size)
{
size_t i, n;
uint8_t *buf_ptr;
buf_ptr = buf;
for(n = 0; nv[n]; ++n);
nghttp2_frame_put_nv_len(buf_ptr, n/2);
buf_ptr += len_size;
for(i = 0; i < n; ++i) {
size_t len = strlen(nv[i]);
nghttp2_frame_put_nv_len(buf_ptr, len);
buf_ptr += len_size;
memcpy(buf_ptr, nv[i], len);
buf_ptr += len;
}
return buf_ptr-buf;
}
static const char *empty_name_headers[] = {
"method", "GET",
"", "https",
"url", "/",
NULL
};
static const char non_ascii_header_name[] = { (char)0xff };
static const char *non_ascii_headers[] = {
non_ascii_header_name, "foo",
NULL
};
void test_nghttp2_frame_unpack_nv_check_name()
{
size_t len_size = 2;
uint8_t nvbuf[1024];
size_t nvbuflen;
nghttp2_buffer buffer;
char **nv;
nghttp2_buffer_init(&buffer, 32);
nvbuflen = nghttp2_pack_nv(nvbuf, sizeof(nvbuf), headers, len_size);
nghttp2_buffer_write(&buffer, nvbuf, nvbuflen);
CU_ASSERT(NGHTTP2_ERR_INVALID_HEADER_BLOCK ==
nghttp2_frame_unpack_nv(&nv, &buffer, len_size));
nghttp2_frame_nv_del(nv);
nghttp2_buffer_reset(&buffer);
nvbuflen = nghttp2_pack_nv(nvbuf, sizeof(nvbuf), empty_name_headers,
len_size);
nghttp2_buffer_write(&buffer, nvbuf, nvbuflen);
CU_ASSERT(NGHTTP2_ERR_INVALID_HEADER_BLOCK ==
nghttp2_frame_unpack_nv(&nv, &buffer, len_size));
nghttp2_frame_nv_del(nv);
nghttp2_buffer_reset(&buffer);
nvbuflen = nghttp2_pack_nv(nvbuf, sizeof(nvbuf), non_ascii_headers,
len_size);
nghttp2_buffer_write(&buffer, nvbuf, nvbuflen);
CU_ASSERT(NGHTTP2_ERR_INVALID_HEADER_BLOCK ==
nghttp2_frame_unpack_nv(&nv, &buffer, len_size));
nghttp2_frame_nv_del(nv);
nghttp2_buffer_free(&buffer);
}
void test_nghttp2_frame_unpack_nv_last_empty_value()
{
size_t len_size = 2;
size_t nvbuflen;
uint8_t nvbuf[256];
uint8_t *nvbufptr;
nghttp2_buffer buffer;
char **outnv = 0;
const char hdname[] = "method";
nvbufptr = nvbuf;
nghttp2_frame_put_nv_len(nvbufptr, 1);
nvbufptr += len_size;
nghttp2_frame_put_nv_len(nvbufptr, sizeof(hdname)-1);
nvbufptr += len_size;
memcpy(nvbufptr, hdname, sizeof(hdname)-1);
nvbufptr += sizeof(hdname)-1;
nghttp2_frame_put_nv_len(nvbufptr, 4);
nvbufptr += len_size;
/* Copy including terminating NULL */
memcpy(nvbufptr, "GET", 4);
nvbufptr += 4;
nvbuflen = nvbufptr - nvbuf;
nghttp2_buffer_init(&buffer, 32);
nghttp2_buffer_write(&buffer, nvbuf, nvbuflen);
CU_ASSERT(NGHTTP2_ERR_INVALID_HEADER_BLOCK ==
nghttp2_frame_unpack_nv(&outnv, &buffer, len_size));
nghttp2_frame_nv_del(outnv);
nghttp2_buffer_free(&buffer);
}
void test_nghttp2_frame_pack_nv_duplicate_keys(void)
{
uint8_t out[1024];
size_t len_size = 2;
const char *nv_src[] = {
"method", "GET",
"scheme", "https",
"url", "/",
"X-hEad", "foo",
"x-heaD", "bar",
"version", "HTTP/1.1",
NULL
};
char **nv = nghttp2_frame_nv_norm_copy(nv_src);
const uint8_t *outptr;
int pairs, len;
/* size_t inlen = */ nghttp2_frame_pack_nv(out, nv, len_size);
outptr = out;
pairs = nghttp2_get_uint16(outptr);
CU_ASSERT(pairs == 5);
outptr += 2;
len = nghttp2_get_uint16(outptr);
outptr += 2;
CU_ASSERT(len == 6);
CU_ASSERT(memcmp(outptr, "method", len) == 0);
outptr += len;
len = nghttp2_get_uint16(outptr);
outptr += 2;
CU_ASSERT(len == 3);
CU_ASSERT(memcmp(outptr, "GET", len) == 0);
outptr += len;
len = nghttp2_get_uint16(outptr);
outptr += 2;
CU_ASSERT(len == 6);
CU_ASSERT(memcmp(outptr, "scheme", len) == 0);
outptr += len;
len = nghttp2_get_uint16(outptr);
outptr += 2;
CU_ASSERT(len == 5);
CU_ASSERT(memcmp(outptr, "https", len) == 0);
outptr += len;
len = nghttp2_get_uint16(outptr);
outptr += 2;
CU_ASSERT(len == 3);
CU_ASSERT(memcmp(outptr, "url", len) == 0);
outptr += len;
len = nghttp2_get_uint16(outptr);
outptr += 2;
CU_ASSERT(len == 1);
CU_ASSERT(memcmp(outptr, "/", len) == 0);
outptr += len;
len = nghttp2_get_uint16(outptr);
outptr += 2;
CU_ASSERT(len == 7);
CU_ASSERT(memcmp(outptr, "version", len) == 0);
outptr += len;
len = nghttp2_get_uint16(outptr);
outptr += 2;
CU_ASSERT(len == 8);
CU_ASSERT(memcmp(outptr, "HTTP/1.1", len) == 0);
outptr += len;
len = nghttp2_get_uint16(outptr);
outptr += 2;
CU_ASSERT(len == 6);
CU_ASSERT(memcmp(outptr, "x-head", len) == 0);
outptr += len;
len = nghttp2_get_uint16(outptr);
outptr += 2;
CU_ASSERT(len == 7);
CU_ASSERT(memcmp(outptr, "foo\0bar", len) == 0);
outptr += len;
nghttp2_frame_nv_del(nv);
}
static const char *multi_empty_headers1[] = {
"a", "",
"a", "",
NULL
};
static const char *multi_empty_headers2[] = {
"a", "/",
"a", "",
NULL
};
static const char *multi_empty_headers3[] = {
"a", "",
"a", "/",
NULL
};
void test_nghttp2_frame_count_nv_space(void)
{
size_t len_size = 2;
CU_ASSERT(85 == nghttp2_frame_count_nv_space((char**)headers, len_size));
len_size = 4;
CU_ASSERT(111 == nghttp2_frame_count_nv_space((char**)headers, len_size));
/* only ("a", "") is counted */
CU_ASSERT(13 == nghttp2_frame_count_nv_space((char**)multi_empty_headers1,
len_size));
/* only ("a", "/") is counted */
CU_ASSERT(14 == nghttp2_frame_count_nv_space((char**)multi_empty_headers2,
len_size));
/* only ("a", "/") is counted */
CU_ASSERT(14 == nghttp2_frame_count_nv_space((char**)multi_empty_headers3,
len_size));
}
static void frame_pack_nv_empty_value_check(uint8_t *outptr,
int vallen,
const char *val,
size_t len_size)
{
int len;
len = get_packed_hd_len(outptr, len_size);
CU_ASSERT(1 == len);
outptr += len_size;
len = get_packed_hd_len(outptr, len_size);
CU_ASSERT(1 == len);
outptr += len_size;
CU_ASSERT(0 == memcmp("a", outptr, len));
outptr += len;
len = get_packed_hd_len(outptr, len_size);
CU_ASSERT(vallen == len);
len += len_size;
if(vallen == len) {
CU_ASSERT(0 == memcmp(val, outptr, vallen));
}
}
void test_nghttp2_frame_pack_nv_empty_value()
{
size_t len_size = 2;
uint8_t out[256];
char **nv;
ssize_t rv;
int off = (len_size == 2 ? -6 : 0);
nv = nghttp2_frame_nv_copy(multi_empty_headers1);
rv = nghttp2_frame_pack_nv(out, nv, len_size);
CU_ASSERT(13+off == rv);
frame_pack_nv_empty_value_check(out, 0, NULL, len_size);
nghttp2_frame_nv_del(nv);
nv = nghttp2_frame_nv_copy(multi_empty_headers2);
rv = nghttp2_frame_pack_nv(out, nv, len_size);
CU_ASSERT(14+off == rv);
frame_pack_nv_empty_value_check(out, 1, "/", len_size);
nghttp2_frame_nv_del(nv);
nv = nghttp2_frame_nv_copy(multi_empty_headers3);
rv = nghttp2_frame_pack_nv(out, nv, len_size);
CU_ASSERT(14+off == rv);
frame_pack_nv_empty_value_check(out, 1, "/", len_size);
nghttp2_frame_nv_del(nv);
}
void test_nghttp2_frame_count_unpack_nv_space(void)
{
size_t nvlen, buflen;
uint8_t out[1024];
size_t len_size = 2;
size_t inlen = nghttp2_frame_pack_nv(out, (char**)headers, len_size);
uint16_t temp;
size_t expected_buflen;
nghttp2_buffer buffer;
uint8_t *chunk;
nghttp2_buffer_init(&buffer, 4096);
nghttp2_buffer_write(&buffer, out, inlen);
CU_ASSERT(0 == nghttp2_frame_count_unpack_nv_space(&nvlen, &buflen,
&buffer, len_size));
CU_ASSERT(7 == nvlen);
expected_buflen = 71+(nvlen*2+1)*sizeof(char*);
CU_ASSERT(expected_buflen == buflen);
chunk = buffer.root.next->data;
/* Change number of nv pair to a bogus value */
temp = nghttp2_get_uint16(chunk);
nghttp2_put_uint16be(chunk, temp+1);
CU_ASSERT(NGHTTP2_ERR_INVALID_FRAME ==
nghttp2_frame_count_unpack_nv_space(&nvlen, &buflen, &buffer,
len_size));
nghttp2_put_uint16be(chunk, temp);
/* Change the length of name to a bogus value */
temp = nghttp2_get_uint16(chunk+2);
nghttp2_put_uint16be(chunk+2, temp+1);
CU_ASSERT(NGHTTP2_ERR_INVALID_FRAME ==
nghttp2_frame_count_unpack_nv_space(&nvlen, &buflen, &buffer,
len_size));
nghttp2_put_uint16be(chunk+2, 65535);
CU_ASSERT(NGHTTP2_ERR_INVALID_FRAME ==
nghttp2_frame_count_unpack_nv_space(&nvlen, &buflen, &buffer,
len_size));
/* Trailing garbage */
nghttp2_buffer_advance(&buffer, 2);
CU_ASSERT(NGHTTP2_ERR_INVALID_FRAME ==
nghttp2_frame_count_unpack_nv_space(&nvlen, &buflen,
&buffer, len_size));
/* We advanced buffer 2 bytes, so it is not valid any more. */
nghttp2_buffer_free(&buffer);
}
void test_nghttp2_frame_nv_sort(void)
{
char *nv[7];
@@ -481,17 +104,21 @@ static void check_frame_header(uint16_t length, uint8_t type, uint8_t flags,
void test_nghttp2_frame_pack_headers()
{
nghttp2_zlib deflater, inflater;
nghttp2_hd_context deflater, inflater;
nghttp2_headers frame, oframe;
uint8_t *buf = NULL, *nvbuf = NULL;
size_t buflen = 0, nvbuflen = 0;
uint8_t *buf = NULL;
size_t buflen = 0;
ssize_t framelen;
nghttp2_zlib_deflate_hd_init(&deflater, 1, 0);
nghttp2_zlib_inflate_hd_init(&inflater, 0);
nghttp2_nv *nva;
ssize_t nvlen;
nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_CLIENT);
nghttp2_hd_inflate_init(&inflater, NGHTTP2_HD_SIDE_SERVER);
nvlen = nghttp2_nv_array_from_cstr(&nva, headers);
nghttp2_frame_headers_init(&frame, NGHTTP2_FLAG_END_STREAM, 1000000007,
1 << 20, nghttp2_frame_nv_copy(headers));
framelen = nghttp2_frame_pack_headers(&buf, &buflen, &nvbuf, &nvbuflen,
&frame, &deflater);
1 << 20, nva, nvlen);
framelen = nghttp2_frame_pack_headers(&buf, &buflen, &frame, &deflater);
CU_ASSERT(0 == unpack_frame_with_nv_block((nghttp2_frame*)&oframe,
NGHTTP2_HEADERS,
@@ -501,16 +128,16 @@ void test_nghttp2_frame_pack_headers()
NGHTTP2_FLAG_END_STREAM, 1000000007, &oframe.hd);
/* We didn't include PRIORITY flag so priority is not packed */
CU_ASSERT(1 << 30 == oframe.pri);
CU_ASSERT(strcmp("method", oframe.nv[0]) == 0);
CU_ASSERT(strcmp("GET", oframe.nv[1]) == 0);
CU_ASSERT(NULL == oframe.nv[14]);
CU_ASSERT(7 == oframe.nvlen);
CU_ASSERT(memcmp("method", oframe.nva[0].name, oframe.nva[0].namelen) == 0);
CU_ASSERT(nvnameeq("method", &oframe.nva[0]));
CU_ASSERT(nvvalueeq("GET", &oframe.nva[0]));
nghttp2_frame_headers_free(&oframe);
memset(&oframe, 0, sizeof(oframe));
/* Next, include PRIORITY flag */
frame.hd.flags |= NGHTTP2_FLAG_PRIORITY;
framelen = nghttp2_frame_pack_headers(&buf, &buflen, &nvbuf, &nvbuflen,
&frame, &deflater);
framelen = nghttp2_frame_pack_headers(&buf, &buflen, &frame, &deflater);
CU_ASSERT(0 == unpack_frame_with_nv_block((nghttp2_frame*)&oframe,
NGHTTP2_HEADERS,
@@ -520,42 +147,42 @@ void test_nghttp2_frame_pack_headers()
NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_PRIORITY,
1000000007, &oframe.hd);
CU_ASSERT(1 << 20 == oframe.pri);
CU_ASSERT(strcmp("method", oframe.nv[0]) == 0);
CU_ASSERT(nvnameeq("method", &oframe.nva[0]));
free(buf);
free(nvbuf);
nghttp2_frame_headers_free(&oframe);
nghttp2_frame_headers_free(&frame);
nghttp2_zlib_inflate_free(&inflater);
nghttp2_zlib_deflate_free(&deflater);
nghttp2_hd_inflate_free(&inflater);
nghttp2_hd_deflate_free(&deflater);
}
void test_nghttp2_frame_pack_headers_frame_too_large(void)
{
nghttp2_zlib deflater;
nghttp2_hd_context deflater;
nghttp2_headers frame;
uint8_t *buf = NULL, *nvbuf = NULL;
size_t buflen = 0, nvbuflen = 0;
uint8_t *buf = NULL;
size_t buflen = 0;
ssize_t framelen;
size_t big_vallen = 1 << 16;
nghttp2_nv *nva;
ssize_t nvlen;
size_t big_vallen = (1 << 16) - 1;
char *big_val = malloc(big_vallen + 1);
const char *big_hds[] = { "header", big_val, NULL };
memset(big_val, '0', big_vallen);
big_val[big_vallen] = '\0';
/* No compression */
nghttp2_zlib_deflate_hd_init(&deflater, 0, 0);
nvlen = nghttp2_nv_array_from_cstr(&nva, big_hds);
nghttp2_hd_deflate_init(&deflater, NGHTTP2_HD_SIDE_CLIENT);
nghttp2_frame_headers_init(&frame, NGHTTP2_FLAG_END_STREAM, 1000000007,
0, nghttp2_frame_nv_copy(big_hds));
framelen = nghttp2_frame_pack_headers(&buf, &buflen,
&nvbuf, &nvbuflen,
&frame, &deflater);
CU_ASSERT_EQUAL(NGHTTP2_ERR_FRAME_TOO_LARGE, framelen);
0, nva, nvlen);
framelen = nghttp2_frame_pack_headers(&buf, &buflen, &frame, &deflater);
printf("framelen=%ld\n", framelen);
CU_ASSERT_EQUAL(NGHTTP2_ERR_HEADER_COMP, framelen);
nghttp2_frame_headers_free(&frame);
free(buf);
free(nvbuf);
free(big_val);
nghttp2_zlib_deflate_free(&deflater);
nghttp2_hd_deflate_free(&deflater);
}
void test_nghttp2_frame_pack_priority(void)

View File

@@ -25,13 +25,6 @@
#ifndef NGHTTP2_FRAME_TEST_H
#define NGHTTP2_FRAME_TEST_H
void test_nghttp2_frame_unpack_nv(void);
void test_nghttp2_frame_unpack_nv_check_name(void);
void test_nghttp2_frame_unpack_nv_last_empty_value(void);
void test_nghttp2_frame_pack_nv_duplicate_keys(void);
void test_nghttp2_frame_count_nv_space(void);
void test_nghttp2_frame_pack_nv_empty_value(void);
void test_nghttp2_frame_count_unpack_nv_space(void);
void test_nghttp2_frame_nv_sort(void);
void test_nghttp2_frame_nv_downcase(void);
void test_nghttp2_frame_nv_check_null(void);

View File

@@ -51,7 +51,6 @@ void test_nghttp2_hd_deflate(void)
MAKE_NV("hello", "world")};
nghttp2_nv nva2[] = {MAKE_NV(":path", "/script.js"),
MAKE_NV(":scheme", "https")};
nghttp2_nv nvtemp;
size_t nv_offset = 12;
uint8_t *buf = NULL;
size_t buflen = 0;
@@ -71,7 +70,7 @@ void test_nghttp2_hd_deflate(void)
assert_nv_equal(nva1, resnva, 3);
nghttp2_nv_array_free(resnva);
nghttp2_nv_array_del(resnva);
nghttp2_hd_end_headers(&inflater);
CU_ASSERT(1 == inflater.refsetlen);
@@ -85,13 +84,9 @@ void test_nghttp2_hd_deflate(void)
CU_ASSERT(2 == nghttp2_hd_inflate_hd(&inflater, &resnva, buf + nv_offset,
blocklen));
/* First and second header fields are interchanged their positions. */
nvtemp = nva2[0];
nva2[0] = nva2[1];
nva2[1] = nvtemp;
assert_nv_equal(nva2, resnva, 2);
nghttp2_nv_array_free(resnva);
nghttp2_nv_array_del(resnva);
nghttp2_hd_end_headers(&inflater);
free(buf);
@@ -118,7 +113,7 @@ void test_nghttp2_hd_inflate_indname_inc(void)
CU_ASSERT(39 == inflater.hd_tablelen);
assert_nv_equal(&nv, &inflater.hd_table[inflater.hd_tablelen-1]->nv, 1);
nghttp2_nv_array_free(resnva);
nghttp2_nv_array_del(resnva);
free(buf);
nghttp2_hd_inflate_free(&inflater);
}
@@ -144,7 +139,7 @@ void test_nghttp2_hd_inflate_indname_inc_eviction(void)
CU_ASSERT(0 == memcmp(":host", resnva[0].name, resnva[0].namelen));
CU_ASSERT(sizeof(value) == resnva[0].valuelen);
nghttp2_nv_array_free(resnva);
nghttp2_nv_array_del(resnva);
nghttp2_hd_end_headers(&inflater);
CU_ASSERT(38 == inflater.hd_tablelen);
@@ -171,7 +166,7 @@ void test_nghttp2_hd_inflate_newname_inc(void)
CU_ASSERT(39 == inflater.hd_tablelen);
assert_nv_equal(&nv, &inflater.hd_table[inflater.hd_tablelen-1]->nv, 1);
nghttp2_nv_array_free(resnva);
nghttp2_nv_array_del(resnva);
free(buf);
nghttp2_hd_inflate_free(&inflater);
}
@@ -195,7 +190,7 @@ void test_nghttp2_hd_inflate_indname_subst(void)
CU_ASSERT(38 == inflater.hd_tablelen);
assert_nv_equal(&nv, &inflater.hd_table[12]->nv, 1);
nghttp2_nv_array_free(resnva);
nghttp2_nv_array_del(resnva);
free(buf);
nghttp2_hd_inflate_free(&inflater);
}
@@ -221,7 +216,7 @@ void test_nghttp2_hd_inflate_indname_subst_eviction(void)
CU_ASSERT(0 == memcmp(":host", resnva[0].name, resnva[0].namelen));
CU_ASSERT(sizeof(value) == resnva[0].valuelen);
nghttp2_nv_array_free(resnva);
nghttp2_nv_array_del(resnva);
nghttp2_hd_end_headers(&inflater);
CU_ASSERT(37 == inflater.hd_tablelen);
@@ -252,7 +247,7 @@ void test_nghttp2_hd_inflate_indname_subst_eviction_neg(void)
CU_ASSERT(0 == memcmp(":host", resnva[0].name, resnva[0].namelen));
CU_ASSERT(sizeof(value) == resnva[0].valuelen);
nghttp2_nv_array_free(resnva);
nghttp2_nv_array_del(resnva);
nghttp2_hd_end_headers(&inflater);
CU_ASSERT(37 == inflater.hd_tablelen);
@@ -279,7 +274,7 @@ void test_nghttp2_hd_inflate_newname_subst(void)
CU_ASSERT(38 == inflater.hd_tablelen);
assert_nv_equal(&nv, &inflater.hd_table[1]->nv, 1);
nghttp2_nv_array_free(resnva);
nghttp2_nv_array_del(resnva);
free(buf);
nghttp2_hd_inflate_free(&inflater);
}

View File

@@ -268,11 +268,6 @@ static void stream_close_callback(nghttp2_session *session, int32_t stream_id,
CU_ASSERT(stream_data != NULL);
}
static char** dup_nv(const char **src)
{
return nghttp2_frame_nv_copy(src);
}
static nghttp2_settings_entry* dup_iv(const nghttp2_settings_entry *iv,
size_t niv)
{
@@ -296,28 +291,17 @@ void test_nghttp2_session_recv(void)
const char *nv[] = {
"url", "/", NULL
};
const char *upcase_nv[] = {
"URL", "/", NULL
};
const char *empty_nv[] = {
NULL
};
const char *mid_nv[] = {
"method", "GET",
"scheme", "https",
"url", "/",
"x-head", "foo",
"x-head", "bar",
"version", "HTTP/1.1",
"x-empty", "",
NULL
};
uint8_t *framedata = NULL, *nvbuf = NULL;
size_t framedatalen = 0, nvbuflen = 0;
uint8_t *framedata = NULL;
size_t framedatalen = 0;
ssize_t framelen;
nghttp2_frame frame;
int i;
nghttp2_outbound_item *item;
nghttp2_nv *nva;
ssize_t nvlen;
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
callbacks.send_callback = null_send_callback;
@@ -325,10 +309,11 @@ void test_nghttp2_session_recv(void)
callbacks.on_frame_recv_callback = on_frame_recv_callback;
user_data.df = &df;
nghttp2_session_server_new(&session, &callbacks, &user_data);
nvlen = nghttp2_nv_array_from_cstr(&nva, nv);
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS,
1, NGHTTP2_PRI_DEFAULT, dup_nv(nv));
1, NGHTTP2_PRI_DEFAULT, nva, nvlen);
framelen = nghttp2_frame_pack_headers(&framedata, &framedatalen,
&nvbuf, &nvbuflen,
&frame.headers,
&session->hd_deflater);
scripted_data_feed_init(&df, framedata, framelen);
@@ -344,29 +329,11 @@ void test_nghttp2_session_recv(void)
}
CU_ASSERT(1 == user_data.frame_recv_cb_called);
/* Receive HEADERS with invalid header block */
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS,
3, NGHTTP2_PRI_DEFAULT, dup_nv(upcase_nv));
framelen = nghttp2_frame_pack_headers(&framedata, &framedatalen,
&nvbuf, &nvbuflen,
&frame.headers,
&session->hd_deflater);
nghttp2_frame_headers_free(&frame.headers);
scripted_data_feed_init(&df, framedata, framelen);
user_data.frame_recv_cb_called = 0;
CU_ASSERT(0 == nghttp2_session_recv(session));
CU_ASSERT(0 == user_data.frame_recv_cb_called);
item = nghttp2_session_get_next_ob_item(session);
CU_ASSERT(NGHTTP2_RST_STREAM == OB_CTRL_TYPE(item));
CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == OB_CTRL(item)->rst_stream.error_code);
CU_ASSERT(0 == nghttp2_session_send(session));
/* Received HEADERS without header block, which is valid */
nvlen = nghttp2_nv_array_from_cstr(&nva, empty_nv);
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS,
5, NGHTTP2_PRI_DEFAULT, dup_nv(empty_nv));
5, NGHTTP2_PRI_DEFAULT, nva, nvlen);
framelen = nghttp2_frame_pack_headers(&framedata, &framedatalen,
&nvbuf, &nvbuflen,
&frame.headers,
&session->hd_deflater);
nghttp2_frame_headers_free(&frame.headers);
@@ -383,25 +350,6 @@ void test_nghttp2_session_recv(void)
/* made max buffer small to cause error intentionally */
session->max_recv_ctrl_frame_buf = 8;
/* Receive HEADERS with too large payload */
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS,
1, NGHTTP2_PRI_DEFAULT, dup_nv(mid_nv));
framelen = nghttp2_frame_pack_headers(&framedata, &framedatalen,
&nvbuf, &nvbuflen,
&frame.headers,
&session->hd_deflater);
nghttp2_frame_headers_free(&frame.headers);
scripted_data_feed_init(&df, framedata, framelen);
user_data.frame_recv_cb_called = 0;
CU_ASSERT(0 == nghttp2_session_recv(session));
CU_ASSERT(0 == user_data.frame_recv_cb_called);
item = nghttp2_session_get_next_ob_item(session);
CU_ASSERT(NGHTTP2_RST_STREAM == OB_CTRL_TYPE(item));
CU_ASSERT(NGHTTP2_FRAME_TOO_LARGE == OB_CTRL(item)->rst_stream.error_code);
CU_ASSERT(1 == OB_CTRL(item)->hd.stream_id);
CU_ASSERT(0 == nghttp2_session_send(session));
/* Receive PING with too large payload */
nghttp2_frame_ping_init(&frame.ping, NGHTTP2_FLAG_NONE, NULL);
nghttp2_reserve_buffer(&framedata, &framedatalen, 77);
@@ -419,33 +367,7 @@ void test_nghttp2_session_recv(void)
CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == OB_CTRL(item)->goaway.error_code);
CU_ASSERT(0 == nghttp2_session_send(session));
nghttp2_session_del(session);
nghttp2_session_client_new(&session, &callbacks, &user_data);
/* Receive HEADERS with invalid header block */
nghttp2_session_open_stream(session, 1, NGHTTP2_FLAG_NONE,
NGHTTP2_PRI_DEFAULT,
NGHTTP2_STREAM_OPENING, NULL);
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS, 1,
NGHTTP2_PRI_DEFAULT, dup_nv(upcase_nv));
framelen = nghttp2_frame_pack_headers(&framedata, &framedatalen,
&nvbuf, &nvbuflen,
&frame.headers,
&session->hd_deflater);
nghttp2_frame_headers_free(&frame.headers);
scripted_data_feed_init(&df, framedata, framelen);
user_data.frame_recv_cb_called = 0;
CU_ASSERT(0 == nghttp2_session_recv(session));
CU_ASSERT(0 == user_data.frame_recv_cb_called);
item = nghttp2_session_get_next_ob_item(session);
CU_ASSERT(NGHTTP2_RST_STREAM == OB_CTRL_TYPE(item));
CU_ASSERT(NGHTTP2_PROTOCOL_ERROR == OB_CTRL(item)->rst_stream.error_code);
CU_ASSERT(0 == nghttp2_session_send(session));
free(framedata);
free(nvbuf);
nghttp2_session_del(session);
}
@@ -456,10 +378,12 @@ void test_nghttp2_session_recv_invalid_stream_id(void)
scripted_data_feed df;
my_user_data user_data;
const char *nv[] = { NULL };
uint8_t *framedata = NULL, *nvbuf = NULL;
size_t framedatalen = 0, nvbuflen = 0;
uint8_t *framedata = NULL;
size_t framedatalen = 0;
ssize_t framelen;
nghttp2_frame frame;
nghttp2_nv *nva;
ssize_t nvlen;
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
callbacks.recv_callback = scripted_recv_callback;
callbacks.on_invalid_frame_recv_callback = on_invalid_frame_recv_callback;
@@ -467,10 +391,10 @@ void test_nghttp2_session_recv_invalid_stream_id(void)
user_data.df = &df;
user_data.invalid_frame_recv_cb_called = 0;
nghttp2_session_server_new(&session, &callbacks, &user_data);
nvlen = nghttp2_nv_array_from_cstr(&nva, nv);
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS, 2,
NGHTTP2_PRI_DEFAULT, dup_nv(nv));
NGHTTP2_PRI_DEFAULT, nva, nvlen);
framelen = nghttp2_frame_pack_headers(&framedata, &framedatalen,
&nvbuf, &nvbuflen,
&frame.headers,
&session->hd_deflater);
scripted_data_feed_init(&df, framedata, framelen);
@@ -480,7 +404,6 @@ void test_nghttp2_session_recv_invalid_stream_id(void)
CU_ASSERT(1 == user_data.invalid_frame_recv_cb_called);
free(framedata);
free(nvbuf);
nghttp2_session_del(session);
}
@@ -493,10 +416,12 @@ void test_nghttp2_session_recv_invalid_frame(void)
const char *nv[] = {
"url", "/", NULL
};
uint8_t *framedata = NULL, *nvbuf = NULL;
size_t framedatalen = 0, nvbuflen = 0;
uint8_t *framedata = NULL;
size_t framedatalen = 0;
ssize_t framelen;
nghttp2_frame frame;
nghttp2_nv *nva;
ssize_t nvlen;
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
callbacks.recv_callback = scripted_recv_callback;
@@ -506,10 +431,10 @@ void test_nghttp2_session_recv_invalid_frame(void)
user_data.df = &df;
user_data.frame_send_cb_called = 0;
nghttp2_session_server_new(&session, &callbacks, &user_data);
nvlen = nghttp2_nv_array_from_cstr(&nva, nv);
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS, 1,
NGHTTP2_PRI_DEFAULT, dup_nv(nv));
NGHTTP2_PRI_DEFAULT, nva, nvlen);
framelen = nghttp2_frame_pack_headers(&framedata, &framedatalen,
&nvbuf, &nvbuflen,
&frame.headers,
&session->hd_deflater);
scripted_data_feed_init(&df, framedata, framelen);
@@ -527,7 +452,6 @@ void test_nghttp2_session_recv_invalid_frame(void)
CU_ASSERT(NGHTTP2_GOAWAY == user_data.sent_frame_type);
free(framedata);
free(nvbuf);
nghttp2_frame_headers_free(&frame.headers);
nghttp2_session_del(session);
@@ -652,6 +576,9 @@ void test_nghttp2_session_add_frame(void)
nghttp2_frame *frame;
nghttp2_headers_aux_data *aux_data =
malloc(sizeof(nghttp2_headers_aux_data));
nghttp2_nv *nva;
ssize_t nvlen;
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
callbacks.send_callback = accumulator_send_callback;
memset(aux_data, 0, sizeof(nghttp2_headers_aux_data));
@@ -660,9 +587,10 @@ void test_nghttp2_session_add_frame(void)
CU_ASSERT(0 == nghttp2_session_client_new(&session, &callbacks, &user_data));
frame = malloc(sizeof(nghttp2_frame));
nvlen = nghttp2_nv_array_from_cstr(&nva, nv);
nghttp2_frame_headers_init(&frame->headers,
NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_PRIORITY,
-1, NGHTTP2_PRI_DEFAULT, dup_nv(nv));
-1, NGHTTP2_PRI_DEFAULT, nva, nvlen);
CU_ASSERT(0 == nghttp2_session_add_frame(session, NGHTTP2_CAT_CTRL, frame,
aux_data));
@@ -685,6 +613,9 @@ void test_nghttp2_session_on_syn_stream_received(void)
nghttp2_frame frame;
nghttp2_stream *stream;
int32_t stream_id = 1;
nghttp2_nv *nva;
ssize_t nvlen;
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
callbacks.on_frame_recv_callback = on_frame_recv_callback;
callbacks.on_invalid_frame_recv_callback = on_invalid_frame_recv_callback;
@@ -692,9 +623,10 @@ void test_nghttp2_session_on_syn_stream_received(void)
user_data.invalid_frame_recv_cb_called = 0;
nghttp2_session_server_new(&session, &callbacks, &user_data);
nvlen = nghttp2_nv_array_from_cstr(&nva, nv);
nghttp2_frame_headers_init(&frame.headers,
NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_PRIORITY,
stream_id, 1 << 20, dup_nv(nv));
stream_id, 1 << 20, nva, nvlen);
CU_ASSERT(0 == nghttp2_session_on_syn_stream_received(session, &frame));
CU_ASSERT(1 == user_data.frame_recv_cb_called);
@@ -706,8 +638,9 @@ void test_nghttp2_session_on_syn_stream_received(void)
/* More than max concurrent streams leads REFUSED_STREAM */
session->local_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS] = 1;
nvlen = nghttp2_nv_array_from_cstr(&nva, nv);
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS,
3, NGHTTP2_PRI_DEFAULT, dup_nv(nv));
3, NGHTTP2_PRI_DEFAULT, nva, nvlen);
user_data.invalid_frame_recv_cb_called = 0;
CU_ASSERT(0 == nghttp2_session_on_syn_stream_received(session, &frame));
CU_ASSERT(1 == user_data.invalid_frame_recv_cb_called);
@@ -719,8 +652,9 @@ void test_nghttp2_session_on_syn_stream_received(void)
/* Stream ID less than or equal to the previouly received SYN_STREAM
leads to connection error */
nvlen = nghttp2_nv_array_from_cstr(&nva, nv);
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS,
3, NGHTTP2_PRI_DEFAULT, dup_nv(nv));
3, NGHTTP2_PRI_DEFAULT, nva, nvlen);
user_data.invalid_frame_recv_cb_called = 0;
CU_ASSERT(0 == nghttp2_session_on_syn_stream_received(session, &frame));
CU_ASSERT(1 == user_data.invalid_frame_recv_cb_called);
@@ -740,6 +674,8 @@ void test_nghttp2_session_on_syn_reply_received(void)
nghttp2_frame frame;
nghttp2_stream *stream;
nghttp2_outbound_item *item;
nghttp2_nv *nva;
ssize_t nvlen;
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
callbacks.on_frame_recv_callback = on_frame_recv_callback;
@@ -751,8 +687,9 @@ void test_nghttp2_session_on_syn_reply_received(void)
stream = nghttp2_session_open_stream(session, 1, NGHTTP2_FLAG_NONE,
NGHTTP2_PRI_DEFAULT,
NGHTTP2_STREAM_OPENING, NULL);
nvlen = nghttp2_nv_array_from_cstr(&nva, nv);
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS, 1,
NGHTTP2_PRI_DEFAULT, dup_nv(nv));
NGHTTP2_PRI_DEFAULT, nva, nvlen);
CU_ASSERT(0 == nghttp2_session_on_syn_reply_received(session, &frame,
stream));
@@ -786,6 +723,9 @@ void test_nghttp2_session_on_headers_received(void)
const char *nv[] = { NULL };
nghttp2_frame frame;
nghttp2_stream *stream;
nghttp2_nv *nva;
ssize_t nvlen;
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
callbacks.on_frame_recv_callback = on_frame_recv_callback;
callbacks.on_invalid_frame_recv_callback = on_invalid_frame_recv_callback;
@@ -797,8 +737,9 @@ void test_nghttp2_session_on_headers_received(void)
NGHTTP2_PRI_DEFAULT,
NGHTTP2_STREAM_OPENED, NULL);
nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_WR);
nvlen = nghttp2_nv_array_from_cstr(&nva, nv);
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS, 1,
NGHTTP2_PRI_DEFAULT, dup_nv(nv));
NGHTTP2_PRI_DEFAULT, nva, nvlen);
CU_ASSERT(0 == nghttp2_session_on_headers_received(session, &frame, stream));
CU_ASSERT(1 == user_data.frame_recv_cb_called);
@@ -1108,13 +1049,17 @@ void test_nghttp2_session_send_headers_start_stream(void)
nghttp2_stream *stream;
nghttp2_headers_aux_data *aux_data =
malloc(sizeof(nghttp2_headers_aux_data));
nghttp2_nv *nva;
ssize_t nvlen;
memset(aux_data, 0, sizeof(nghttp2_headers_aux_data));
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
callbacks.send_callback = null_send_callback;
nghttp2_session_client_new(&session, &callbacks, NULL);
nvlen = nghttp2_nv_array_from_cstr(&nva, nv);
nghttp2_frame_headers_init(&frame->headers, NGHTTP2_FLAG_END_HEADERS, -1,
NGHTTP2_PRI_DEFAULT, dup_nv(nv));
NGHTTP2_PRI_DEFAULT, nva, nvlen);
nghttp2_session_add_frame(session, NGHTTP2_CAT_CTRL, frame, aux_data);
CU_ASSERT(0 == nghttp2_session_send(session));
stream = nghttp2_session_get_stream(session, 1);
@@ -1130,6 +1075,8 @@ void test_nghttp2_session_send_headers_reply(void)
const char *nv[] = { NULL };
nghttp2_frame *frame = malloc(sizeof(nghttp2_frame));
nghttp2_stream *stream;
nghttp2_nv *nva;
ssize_t nvlen;
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
callbacks.send_callback = null_send_callback;
@@ -1138,8 +1085,9 @@ void test_nghttp2_session_send_headers_reply(void)
nghttp2_session_open_stream(session, 2, NGHTTP2_FLAG_NONE,
NGHTTP2_PRI_DEFAULT,
NGHTTP2_STREAM_OPENING, NULL);
nvlen = nghttp2_nv_array_from_cstr(&nva, nv);
nghttp2_frame_headers_init(&frame->headers, NGHTTP2_FLAG_END_HEADERS, 2,
NGHTTP2_PRI_DEFAULT, dup_nv(nv));
NGHTTP2_PRI_DEFAULT, nva, nvlen);
nghttp2_session_add_frame(session, NGHTTP2_CAT_CTRL, frame, NULL);
CU_ASSERT(0 == nghttp2_session_send(session));
stream = nghttp2_session_get_stream(session, 2);
@@ -1213,7 +1161,7 @@ void test_nghttp2_submit_response(void)
NGHTTP2_STREAM_OPENING, NULL);
CU_ASSERT(0 == nghttp2_submit_response(session, 2, nv, &data_prd));
item = nghttp2_session_get_next_ob_item(session);
CU_ASSERT(0 == strcmp("content-length", OB_CTRL(item)->headers.nv[0]));
CU_ASSERT(nvnameeq("content-length", &OB_CTRL(item)->headers.nva[0]));
CU_ASSERT(0 == nghttp2_session_send(session));
nghttp2_session_del(session);
}
@@ -1239,14 +1187,14 @@ void test_nghttp2_submit_response_without_data(void)
NGHTTP2_STREAM_OPENING, NULL);
CU_ASSERT(0 == nghttp2_submit_response(session, 1, nv, &data_prd));
item = nghttp2_session_get_next_ob_item(session);
CU_ASSERT(0 == strcmp(":version", OB_CTRL(item)->headers.nv[0]));
CU_ASSERT(nvnameeq(":version", &OB_CTRL(item)->headers.nva[0]));
CU_ASSERT(OB_CTRL(item)->hd.flags & NGHTTP2_FLAG_END_STREAM);
CU_ASSERT(0 == nghttp2_session_send(session));
CU_ASSERT(0 == unpack_frame_with_nv_block(&frame, NGHTTP2_HEADERS,
&session->hd_inflater,
acc.buf, acc.length));
CU_ASSERT(0 == strcmp(":version", frame.headers.nv[0]));
CU_ASSERT(nvnameeq(":version", &frame.headers.nva[0]));
nghttp2_frame_headers_free(&frame.headers);
nghttp2_session_del(session);
@@ -1270,7 +1218,7 @@ void test_nghttp2_submit_request_with_data(void)
CU_ASSERT(0 == nghttp2_submit_request(session, NGHTTP2_PRI_DEFAULT, nv,
&data_prd, NULL));
item = nghttp2_session_get_next_ob_item(session);
CU_ASSERT(0 == strcmp(":version", OB_CTRL(item)->headers.nv[0]));
CU_ASSERT(nvnameeq(":version", &OB_CTRL(item)->headers.nva[0]));
CU_ASSERT(0 == nghttp2_session_send(session));
CU_ASSERT(0 == ud.data_source_length);
@@ -1296,14 +1244,14 @@ void test_nghttp2_submit_request_without_data(void)
CU_ASSERT(0 == nghttp2_submit_request(session, NGHTTP2_PRI_DEFAULT, nv,
&data_prd, NULL));
item = nghttp2_session_get_next_ob_item(session);
CU_ASSERT(0 == strcmp(":version", OB_CTRL(item)->headers.nv[0]));
CU_ASSERT(nvnameeq(":version", &OB_CTRL(item)->headers.nva[0]));
CU_ASSERT(OB_CTRL(item)->hd.flags & NGHTTP2_FLAG_END_STREAM);
CU_ASSERT(0 == nghttp2_session_send(session));
CU_ASSERT(0 == unpack_frame_with_nv_block(&frame, NGHTTP2_HEADERS,
&session->hd_inflater,
acc.buf, acc.length));
CU_ASSERT(0 == strcmp(":version", frame.headers.nv[0]));
CU_ASSERT(nvnameeq(":version", &frame.headers.nva[0]));
nghttp2_frame_headers_free(&frame.headers);
nghttp2_session_del(session);
@@ -1324,7 +1272,7 @@ void test_nghttp2_submit_headers_start_stream(void)
-1, NGHTTP2_PRI_DEFAULT,
nv, NULL));
item = nghttp2_session_get_next_ob_item(session);
CU_ASSERT(0 == strcmp(":version", OB_CTRL(item)->headers.nv[0]));
CU_ASSERT(nvnameeq(":version", &OB_CTRL(item)->headers.nva[0]));
CU_ASSERT((NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_END_STREAM) ==
OB_CTRL(item)->hd.flags);
CU_ASSERT(NGHTTP2_PRI_DEFAULT == OB_CTRL(item)->headers.pri);
@@ -1351,7 +1299,7 @@ void test_nghttp2_submit_headers_reply(void)
1, NGHTTP2_PRI_DEFAULT,
nv, NULL));
item = nghttp2_session_get_next_ob_item(session);
CU_ASSERT(0 == strcmp(":version", OB_CTRL(item)->headers.nv[0]));
CU_ASSERT(nvnameeq(":version", &OB_CTRL(item)->headers.nva[0]));
CU_ASSERT((NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS) ==
OB_CTRL(item)->hd.flags);
@@ -1402,7 +1350,7 @@ void test_nghttp2_submit_headers(void)
1, NGHTTP2_PRI_DEFAULT,
nv, NULL));
item = nghttp2_session_get_next_ob_item(session);
CU_ASSERT(0 == strcmp(":version", OB_CTRL(item)->headers.nv[0]));
CU_ASSERT(nvnameeq(":version", &OB_CTRL(item)->headers.nva[0]));
CU_ASSERT((NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_END_HEADERS) ==
OB_CTRL(item)->hd.flags);
@@ -1430,7 +1378,7 @@ void test_nghttp2_submit_headers(void)
NGHTTP2_HEADERS,
&session->hd_inflater,
acc.buf, acc.length));
CU_ASSERT(0 == strcmp(":version", frame.headers.nv[0]));
CU_ASSERT(nvnameeq(":version", &frame.headers.nva[0]));
nghttp2_frame_headers_free(&frame.headers);
nghttp2_session_del(session);
@@ -1734,14 +1682,17 @@ void test_nghttp2_session_max_concurrent_streams(void)
nghttp2_frame frame;
const char *nv[] = { NULL };
nghttp2_outbound_item *item;
nghttp2_nv *nva;
ssize_t nvlen;
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
nghttp2_session_server_new(&session, &callbacks, NULL);
nghttp2_session_open_stream(session, 1, NGHTTP2_FLAG_NONE,
NGHTTP2_PRI_DEFAULT,
NGHTTP2_STREAM_OPENED, NULL);
nvlen = nghttp2_nv_array_from_cstr(&nva, nv);
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_NONE, 3,
NGHTTP2_PRI_DEFAULT, dup_nv(nv));
NGHTTP2_PRI_DEFAULT, nva, nvlen);
session->local_settings[NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS] = 1;
CU_ASSERT(0 == nghttp2_session_on_syn_stream_received(session, &frame));
@@ -2125,13 +2076,17 @@ void test_nghttp2_session_on_request_recv_callback(void)
const char *nv[] = { NULL };
nghttp2_frame frame;
nghttp2_stream *stream;
nghttp2_nv *nva;
ssize_t nvlen;
memset(&callbacks, 0, sizeof(nghttp2_session_callbacks));
callbacks.on_request_recv_callback = on_request_recv_callback;
user_data.stream_id = 0;
nghttp2_session_server_new(&session, &callbacks, &user_data);
nvlen = nghttp2_nv_array_from_cstr(&nva, nv);
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS,
1, NGHTTP2_PRI_DEFAULT, dup_nv(nv));
1, NGHTTP2_PRI_DEFAULT, nva, nvlen);
CU_ASSERT(0 == nghttp2_session_on_syn_stream_received(session, &frame));
CU_ASSERT(0 == user_data.stream_id);
@@ -2148,8 +2103,9 @@ void test_nghttp2_session_on_request_recv_callback(void)
stream = nghttp2_session_open_stream(session, 5, NGHTTP2_FLAG_NONE,
NGHTTP2_PRI_DEFAULT,
NGHTTP2_STREAM_OPENING, NULL);
nvlen = nghttp2_nv_array_from_cstr(&nva, nv);
nghttp2_frame_headers_init(&frame.headers, NGHTTP2_FLAG_END_HEADERS,
5, NGHTTP2_PRI_DEFAULT, dup_nv(nv));
5, NGHTTP2_PRI_DEFAULT, nva, nvlen);
CU_ASSERT(0 == nghttp2_session_on_headers_received(session, &frame, stream));
CU_ASSERT(0 == user_data.stream_id);

View File

@@ -32,33 +32,22 @@
ssize_t unpack_frame_with_nv_block(nghttp2_frame *frame,
nghttp2_frame_type type,
nghttp2_zlib *inflater,
nghttp2_hd_context *inflater,
const uint8_t *in, size_t len)
{
nghttp2_buffer buffer;
ssize_t rv;
ssize_t pnvlen;
pnvlen = nghttp2_frame_nv_offset(in);
assert(pnvlen > 0);
nghttp2_buffer_init(&buffer, 4096);
rv = nghttp2_zlib_inflate_hd(inflater, &buffer, &in[pnvlen], len - pnvlen);
if(rv < 0) {
return rv;
}
switch(type) {
case NGHTTP2_HEADERS:
rv = nghttp2_frame_unpack_headers((nghttp2_headers*)frame,
&in[0], NGHTTP2_FRAME_HEAD_LENGTH,
&in[NGHTTP2_FRAME_HEAD_LENGTH],
pnvlen - NGHTTP2_FRAME_HEAD_LENGTH,
&buffer);
len - NGHTTP2_FRAME_HEAD_LENGTH,
inflater);
break;
default:
/* Must not be reachable */
assert(0);
}
nghttp2_buffer_free(&buffer);
return rv;
}
@@ -70,3 +59,24 @@ char* strcopy(const char* s)
dest[len] = '\0';
return dest;
}
int strmemeq(const char *a, const uint8_t *b, size_t bn)
{
const uint8_t *c;
if(!a || !b) {
return 0;
}
c = b + bn;
for(; *a && b != c && *a == *b; ++a, ++b);
return !*a && b == c;
}
int nvnameeq(const char *a, nghttp2_nv *nv)
{
return strmemeq(a, nv->name, nv->namelen);
}
int nvvalueeq(const char *a, nghttp2_nv *nv)
{
return strmemeq(a, nv->value, nv->valuelen);
}

View File

@@ -30,13 +30,19 @@
#endif /* HAVE_CONFIG_H */
#include "nghttp2_frame.h"
#include "nghttp2_zlib.h"
#include "nghttp2_hd.h"
ssize_t unpack_frame_with_nv_block(nghttp2_frame *frame,
nghttp2_frame_type type,
nghttp2_zlib *inflater,
nghttp2_hd_context *inflater,
const uint8_t *in, size_t len);
char* strcopy(const char* s);
int strmemeq(const char *a, const uint8_t *b, size_t bn);
int nvnameeq(const char *a, nghttp2_nv *nv);
int nvvalueeq(const char *a, nghttp2_nv *nv);
#endif /* NGHTTP2_TEST_HELPER_H */