2013-07-19 09:50:31 +02:00
|
|
|
/*
|
2014-03-30 12:09:21 +02:00
|
|
|
* nghttp2 - HTTP/2 C Library
|
2013-07-19 09:50:31 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 2013 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#include "nghttp2_hd_test.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <CUnit/CUnit.h>
|
|
|
|
|
|
|
|
#include "nghttp2_hd.h"
|
|
|
|
#include "nghttp2_frame.h"
|
2013-09-10 17:55:35 +02:00
|
|
|
#include "nghttp2_test_helper.h"
|
2013-07-19 09:50:31 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void test_nghttp2_hd_deflate(void) {
|
2014-01-26 09:53:04 +01:00
|
|
|
nghttp2_hd_deflater deflater;
|
|
|
|
nghttp2_hd_inflater inflater;
|
2013-07-19 09:50:31 +02:00
|
|
|
nghttp2_nv nva1[] = {MAKE_NV(":path", "/my-example/index.html"),
|
2014-11-27 15:39:04 +01:00
|
|
|
MAKE_NV(":scheme", "https"), MAKE_NV("hello", "world")};
|
2013-07-19 09:50:31 +02:00
|
|
|
nghttp2_nv nva2[] = {MAKE_NV(":path", "/script.js"),
|
|
|
|
MAKE_NV(":scheme", "https")};
|
2014-11-27 15:39:04 +01:00
|
|
|
nghttp2_nv nva3[] = {MAKE_NV("cookie", "k1=v1"), MAKE_NV("cookie", "k2=v2"),
|
2013-07-25 18:34:28 +02:00
|
|
|
MAKE_NV("via", "proxy")};
|
2013-07-22 19:52:08 +02:00
|
|
|
nghttp2_nv nva4[] = {MAKE_NV(":path", "/style.css"),
|
2014-11-27 15:39:04 +01:00
|
|
|
MAKE_NV("cookie", "k1=v1"), MAKE_NV("cookie", "k1=v1")};
|
2013-07-23 16:10:53 +02:00
|
|
|
nghttp2_nv nva5[] = {MAKE_NV(":path", "/style.css"),
|
|
|
|
MAKE_NV("x-nghttp2", "")};
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs bufs;
|
2013-07-19 09:50:31 +02:00
|
|
|
ssize_t blocklen;
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out out;
|
2014-03-13 14:11:02 +01:00
|
|
|
int rv;
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem *mem;
|
2013-07-19 09:50:31 +02:00
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
mem = nghttp2_mem_default();
|
2014-03-13 14:11:02 +01:00
|
|
|
frame_pack_bufs_init(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out_init(&out);
|
2014-12-07 15:07:13 +01:00
|
|
|
CU_ASSERT(0 == nghttp2_hd_deflate_init(&deflater, mem));
|
|
|
|
CU_ASSERT(0 == nghttp2_hd_inflate_init(&inflater, mem));
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-05-13 16:42:55 +02:00
|
|
|
rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva1, ARRLEN(nva1));
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
CU_ASSERT(0 == rv);
|
2013-07-19 18:19:00 +02:00
|
|
|
CU_ASSERT(blocklen > 0);
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2013-07-19 09:50:31 +02:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
CU_ASSERT(3 == out.nvlen);
|
2015-03-03 15:23:43 +01:00
|
|
|
assert_nv_equal(nva1, out.nva, 3, mem);
|
2014-01-16 15:41:13 +01:00
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
2013-07-19 09:50:31 +02:00
|
|
|
|
|
|
|
/* Second headers */
|
2014-05-13 16:42:55 +02:00
|
|
|
rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva2, ARRLEN(nva2));
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
CU_ASSERT(0 == rv);
|
2013-07-19 18:19:00 +02:00
|
|
|
CU_ASSERT(blocklen > 0);
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2013-07-19 09:50:31 +02:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
CU_ASSERT(2 == out.nvlen);
|
2015-03-03 15:23:43 +01:00
|
|
|
assert_nv_equal(nva2, out.nva, 2, mem);
|
2013-07-19 09:50:31 +02:00
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
2013-07-19 09:50:31 +02:00
|
|
|
|
2013-07-22 19:52:08 +02:00
|
|
|
/* Third headers, including same header field name, but value is not
|
|
|
|
the same. */
|
2014-05-13 16:42:55 +02:00
|
|
|
rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva3, ARRLEN(nva3));
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
CU_ASSERT(0 == rv);
|
2013-07-22 19:52:08 +02:00
|
|
|
CU_ASSERT(blocklen > 0);
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2013-07-22 19:52:08 +02:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
CU_ASSERT(3 == out.nvlen);
|
2015-03-03 15:23:43 +01:00
|
|
|
assert_nv_equal(nva3, out.nva, 3, mem);
|
2014-01-16 15:41:13 +01:00
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
2013-07-22 19:52:08 +02:00
|
|
|
|
2013-08-23 16:38:28 +02:00
|
|
|
/* Fourth headers, including duplicate header fields. */
|
2014-05-13 16:42:55 +02:00
|
|
|
rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva4, ARRLEN(nva4));
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
CU_ASSERT(0 == rv);
|
2013-07-25 18:34:28 +02:00
|
|
|
CU_ASSERT(blocklen > 0);
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2013-07-22 19:52:08 +02:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
CU_ASSERT(3 == out.nvlen);
|
2015-03-03 15:23:43 +01:00
|
|
|
assert_nv_equal(nva4, out.nva, 3, mem);
|
2013-07-22 19:52:08 +02:00
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
2013-07-22 19:52:08 +02:00
|
|
|
|
2013-07-23 16:10:53 +02:00
|
|
|
/* Fifth headers includes empty value */
|
2014-05-13 16:42:55 +02:00
|
|
|
rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva5, ARRLEN(nva5));
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
CU_ASSERT(0 == rv);
|
2013-07-23 16:10:53 +02:00
|
|
|
CU_ASSERT(blocklen > 0);
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2013-07-23 16:10:53 +02:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
CU_ASSERT(2 == out.nvlen);
|
2015-03-03 15:23:43 +01:00
|
|
|
assert_nv_equal(nva5, out.nva, 2, mem);
|
2013-07-23 16:10:53 +02:00
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
2013-07-23 16:10:53 +02:00
|
|
|
|
|
|
|
/* Cleanup */
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_free(&bufs);
|
2013-07-19 09:50:31 +02:00
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
|
|
|
nghttp2_hd_deflate_free(&deflater);
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void test_nghttp2_hd_deflate_same_indexed_repr(void) {
|
2014-01-26 09:53:04 +01:00
|
|
|
nghttp2_hd_deflater deflater;
|
|
|
|
nghttp2_hd_inflater inflater;
|
2015-04-14 18:21:27 +02:00
|
|
|
nghttp2_nv nva1[] = {MAKE_NV("host", "alpha"), MAKE_NV("host", "alpha")};
|
|
|
|
nghttp2_nv nva2[] = {MAKE_NV("host", "alpha"), MAKE_NV("host", "alpha"),
|
|
|
|
MAKE_NV("host", "alpha")};
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs bufs;
|
2013-08-23 16:38:28 +02:00
|
|
|
ssize_t blocklen;
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out out;
|
2014-03-13 14:11:02 +01:00
|
|
|
int rv;
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem *mem;
|
2013-08-23 16:38:28 +02:00
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
mem = nghttp2_mem_default();
|
2014-03-13 14:11:02 +01:00
|
|
|
frame_pack_bufs_init(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out_init(&out);
|
2014-12-07 15:07:13 +01:00
|
|
|
CU_ASSERT(0 == nghttp2_hd_deflate_init(&deflater, mem));
|
|
|
|
CU_ASSERT(0 == nghttp2_hd_inflate_init(&inflater, mem));
|
2013-08-23 16:38:28 +02:00
|
|
|
|
2014-07-12 11:47:55 +02:00
|
|
|
/* Encode 2 same headers. Emit 1 literal reprs and 1 index repr. */
|
2014-05-13 16:42:55 +02:00
|
|
|
rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva1, ARRLEN(nva1));
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
CU_ASSERT(0 == rv);
|
2013-08-23 16:38:28 +02:00
|
|
|
CU_ASSERT(blocklen > 0);
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2013-08-23 16:38:28 +02:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
CU_ASSERT(2 == out.nvlen);
|
2015-03-03 15:23:43 +01:00
|
|
|
assert_nv_equal(nva1, out.nva, 2, mem);
|
2013-08-23 16:38:28 +02:00
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
2013-08-23 16:38:28 +02:00
|
|
|
|
2014-07-12 11:47:55 +02:00
|
|
|
/* Encode 3 same headers. This time, emits 3 index reprs. */
|
2014-05-13 16:42:55 +02:00
|
|
|
rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva2, ARRLEN(nva2));
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
CU_ASSERT(0 == rv);
|
2014-07-12 11:47:55 +02:00
|
|
|
CU_ASSERT(blocklen == 3);
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2013-08-23 16:38:28 +02:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
CU_ASSERT(3 == out.nvlen);
|
2015-03-03 15:23:43 +01:00
|
|
|
assert_nv_equal(nva2, out.nva, 3, mem);
|
2013-08-23 16:38:28 +02:00
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
2013-08-23 16:38:28 +02:00
|
|
|
|
|
|
|
/* Cleanup */
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_free(&bufs);
|
2013-08-23 16:38:28 +02:00
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
|
|
|
nghttp2_hd_deflate_free(&deflater);
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void test_nghttp2_hd_inflate_indexed(void) {
|
2014-05-01 02:06:54 +02:00
|
|
|
nghttp2_hd_inflater inflater;
|
|
|
|
nghttp2_bufs bufs;
|
|
|
|
ssize_t blocklen;
|
|
|
|
nghttp2_nv nv = MAKE_NV(":path", "/");
|
|
|
|
nva_out out;
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem *mem;
|
2014-05-01 02:06:54 +02:00
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
mem = nghttp2_mem_default();
|
2014-05-01 02:06:54 +02:00
|
|
|
frame_pack_bufs_init(&bufs);
|
|
|
|
|
|
|
|
nva_out_init(&out);
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_hd_inflate_init(&inflater, mem);
|
2014-05-01 02:06:54 +02:00
|
|
|
|
|
|
|
nghttp2_bufs_addb(&bufs, (1 << 7) | 4);
|
|
|
|
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-05-01 02:06:54 +02:00
|
|
|
|
|
|
|
CU_ASSERT(1 == blocklen);
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2014-05-01 02:06:54 +02:00
|
|
|
|
|
|
|
CU_ASSERT(1 == out.nvlen);
|
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
assert_nv_equal(&nv, out.nva, 1, mem);
|
2014-05-01 02:06:54 +02:00
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-05-01 02:06:54 +02:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
|
|
|
|
|
|
|
/* index = 0 is error */
|
|
|
|
nghttp2_bufs_addb(&bufs, 1 << 7);
|
|
|
|
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-05-01 02:06:54 +02:00
|
|
|
|
|
|
|
CU_ASSERT(1 == blocklen);
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(NGHTTP2_ERR_HEADER_COMP ==
|
|
|
|
inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2014-05-01 02:06:54 +02:00
|
|
|
|
|
|
|
nghttp2_bufs_free(&bufs);
|
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void test_nghttp2_hd_inflate_indname_noinc(void) {
|
2014-01-26 09:53:04 +01:00
|
|
|
nghttp2_hd_inflater inflater;
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs bufs;
|
2014-03-10 17:47:38 +01:00
|
|
|
ssize_t blocklen;
|
2014-11-27 15:39:04 +01:00
|
|
|
nghttp2_nv nv[] = {/* Huffman */
|
|
|
|
MAKE_NV("user-agent", "nghttp2"),
|
|
|
|
/* Expecting no huffman */
|
|
|
|
MAKE_NV("user-agent", "x")};
|
2013-11-03 10:30:57 +01:00
|
|
|
size_t i;
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out out;
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem *mem;
|
2013-11-03 10:30:57 +01:00
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
mem = nghttp2_mem_default();
|
2014-03-13 14:11:02 +01:00
|
|
|
frame_pack_bufs_init(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out_init(&out);
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_hd_inflate_init(&inflater, mem);
|
2013-11-03 10:30:57 +01:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
for (i = 0; i < ARRLEN(nv); ++i) {
|
2015-04-14 18:21:27 +02:00
|
|
|
CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&bufs, 57, &nv[i],
|
|
|
|
NGHTTP2_HD_WITHOUT_INDEXING));
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
|
|
|
CU_ASSERT(blocklen > 0);
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2014-01-16 15:41:13 +01:00
|
|
|
|
|
|
|
CU_ASSERT(1 == out.nvlen);
|
2015-03-03 15:23:43 +01:00
|
|
|
assert_nv_equal(&nv[i], out.nva, 1, mem);
|
2014-01-26 09:53:04 +01:00
|
|
|
CU_ASSERT(0 == inflater.ctx.hd_table.len);
|
2015-10-21 17:57:00 +02:00
|
|
|
CU_ASSERT(61 == nghttp2_hd_inflate_get_num_table_entries(&inflater));
|
2013-11-03 10:30:57 +01:00
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
2013-11-03 10:30:57 +01:00
|
|
|
}
|
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_free(&bufs);
|
2013-11-03 10:30:57 +01:00
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void test_nghttp2_hd_inflate_indname_inc(void) {
|
2014-01-26 09:53:04 +01:00
|
|
|
nghttp2_hd_inflater inflater;
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs bufs;
|
2014-03-10 17:47:38 +01:00
|
|
|
ssize_t blocklen;
|
2013-07-19 09:50:31 +02:00
|
|
|
nghttp2_nv nv = MAKE_NV("user-agent", "nghttp2");
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out out;
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem *mem;
|
2014-01-16 15:41:13 +01:00
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
mem = nghttp2_mem_default();
|
2014-03-13 14:11:02 +01:00
|
|
|
frame_pack_bufs_init(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out_init(&out);
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_hd_inflate_init(&inflater, mem);
|
2013-07-19 09:50:31 +02:00
|
|
|
|
2015-04-14 18:21:27 +02:00
|
|
|
CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&bufs, 57, &nv,
|
|
|
|
NGHTTP2_HD_WITH_INDEXING));
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
|
|
|
CU_ASSERT(blocklen > 0);
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2014-01-16 15:41:13 +01:00
|
|
|
|
|
|
|
CU_ASSERT(1 == out.nvlen);
|
2015-03-03 15:23:43 +01:00
|
|
|
assert_nv_equal(&nv, out.nva, 1, mem);
|
2014-01-26 09:53:04 +01:00
|
|
|
CU_ASSERT(1 == inflater.ctx.hd_table.len);
|
2015-10-21 17:57:00 +02:00
|
|
|
CU_ASSERT(62 == nghttp2_hd_inflate_get_num_table_entries(&inflater));
|
|
|
|
assert_nv_equal(&nv,
|
|
|
|
&nghttp2_hd_table_get(&inflater.ctx,
|
|
|
|
NGHTTP2_STATIC_TABLE_LENGTH +
|
|
|
|
inflater.ctx.hd_table.len - 1)->nv,
|
|
|
|
1, mem);
|
|
|
|
assert_nv_equal(&nv, nghttp2_hd_inflate_get_table_entry(
|
|
|
|
&inflater, NGHTTP2_STATIC_TABLE_LENGTH +
|
|
|
|
inflater.ctx.hd_table.len),
|
|
|
|
1, mem);
|
2013-07-19 09:50:31 +02:00
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_free(&bufs);
|
2013-07-19 09:50:31 +02:00
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void test_nghttp2_hd_inflate_indname_inc_eviction(void) {
|
2014-01-26 09:53:04 +01:00
|
|
|
nghttp2_hd_inflater inflater;
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs bufs;
|
2014-03-10 17:47:38 +01:00
|
|
|
ssize_t blocklen;
|
2015-03-23 15:25:57 +01:00
|
|
|
uint8_t value[1025];
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out out;
|
2014-04-01 18:25:44 +02:00
|
|
|
nghttp2_nv nv;
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem *mem;
|
2014-01-16 15:41:13 +01:00
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
mem = nghttp2_mem_default();
|
2014-03-13 14:11:02 +01:00
|
|
|
frame_pack_bufs_init(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out_init(&out);
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_hd_inflate_init(&inflater, mem);
|
2013-07-19 09:50:31 +02:00
|
|
|
|
2013-08-22 18:28:01 +02:00
|
|
|
memset(value, '0', sizeof(value));
|
2015-03-23 15:25:57 +01:00
|
|
|
value[sizeof(value) - 1] = '\0';
|
2014-04-01 18:25:44 +02:00
|
|
|
nv.value = value;
|
2015-03-23 15:25:57 +01:00
|
|
|
nv.valuelen = sizeof(value) - 1;
|
2014-04-01 18:25:44 +02:00
|
|
|
|
|
|
|
nv.flags = NGHTTP2_NV_FLAG_NONE;
|
|
|
|
|
2015-04-14 18:21:27 +02:00
|
|
|
CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&bufs, 14, &nv,
|
|
|
|
NGHTTP2_HD_WITH_INDEXING));
|
|
|
|
CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&bufs, 15, &nv,
|
|
|
|
NGHTTP2_HD_WITH_INDEXING));
|
|
|
|
CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&bufs, 16, &nv,
|
|
|
|
NGHTTP2_HD_WITH_INDEXING));
|
|
|
|
CU_ASSERT(0 == nghttp2_hd_emit_indname_block(&bufs, 17, &nv,
|
|
|
|
NGHTTP2_HD_WITH_INDEXING));
|
2013-10-12 14:49:01 +02:00
|
|
|
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
|
|
|
CU_ASSERT(blocklen > 0);
|
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2013-07-19 09:50:31 +02:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
CU_ASSERT(4 == out.nvlen);
|
|
|
|
CU_ASSERT(14 == out.nva[0].namelen);
|
|
|
|
CU_ASSERT(0 == memcmp("accept-charset", out.nva[0].name, out.nva[0].namelen));
|
2015-03-23 15:25:57 +01:00
|
|
|
CU_ASSERT(sizeof(value) - 1 == out.nva[0].valuelen);
|
2014-01-16 15:41:13 +01:00
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
2013-07-19 09:50:31 +02:00
|
|
|
|
2014-01-26 09:53:04 +01:00
|
|
|
CU_ASSERT(3 == inflater.ctx.hd_table.len);
|
2015-10-21 17:57:00 +02:00
|
|
|
CU_ASSERT(64 == nghttp2_hd_inflate_get_num_table_entries(&inflater));
|
2013-07-19 09:50:31 +02:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_free(&bufs);
|
2013-11-03 10:30:57 +01:00
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void test_nghttp2_hd_inflate_newname_noinc(void) {
|
2014-01-26 09:53:04 +01:00
|
|
|
nghttp2_hd_inflater inflater;
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs bufs;
|
2014-03-10 17:47:38 +01:00
|
|
|
ssize_t blocklen;
|
2014-11-27 15:39:04 +01:00
|
|
|
nghttp2_nv nv[] = {/* Expecting huffman for both */
|
|
|
|
MAKE_NV("my-long-content-length", "nghttp2"),
|
|
|
|
/* Expecting no huffman for both */
|
|
|
|
MAKE_NV("x", "y"),
|
|
|
|
/* Huffman for key only */
|
|
|
|
MAKE_NV("my-long-content-length", "y"),
|
|
|
|
/* Huffman for value only */
|
|
|
|
MAKE_NV("x", "nghttp2")};
|
2013-11-03 10:30:57 +01:00
|
|
|
size_t i;
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out out;
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem *mem;
|
2013-11-03 10:30:57 +01:00
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
mem = nghttp2_mem_default();
|
2014-03-13 14:11:02 +01:00
|
|
|
frame_pack_bufs_init(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out_init(&out);
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_hd_inflate_init(&inflater, mem);
|
2014-11-27 15:39:04 +01:00
|
|
|
for (i = 0; i < ARRLEN(nv); ++i) {
|
2015-04-14 18:21:27 +02:00
|
|
|
CU_ASSERT(0 == nghttp2_hd_emit_newname_block(&bufs, &nv[i],
|
|
|
|
NGHTTP2_HD_WITHOUT_INDEXING));
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
|
|
|
CU_ASSERT(blocklen > 0);
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2014-01-16 15:41:13 +01:00
|
|
|
|
|
|
|
CU_ASSERT(1 == out.nvlen);
|
2015-03-03 15:23:43 +01:00
|
|
|
assert_nv_equal(&nv[i], out.nva, 1, mem);
|
2014-01-26 09:53:04 +01:00
|
|
|
CU_ASSERT(0 == inflater.ctx.hd_table.len);
|
2013-11-03 10:30:57 +01:00
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
2013-11-03 10:30:57 +01:00
|
|
|
}
|
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_free(&bufs);
|
2013-07-19 09:50:31 +02:00
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void test_nghttp2_hd_inflate_newname_inc(void) {
|
2014-01-26 09:53:04 +01:00
|
|
|
nghttp2_hd_inflater inflater;
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs bufs;
|
2014-03-10 17:47:38 +01:00
|
|
|
ssize_t blocklen;
|
2013-07-19 09:50:31 +02:00
|
|
|
nghttp2_nv nv = MAKE_NV("x-rel", "nghttp2");
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out out;
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem *mem;
|
2014-01-16 15:41:13 +01:00
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
mem = nghttp2_mem_default();
|
2014-03-13 14:11:02 +01:00
|
|
|
frame_pack_bufs_init(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out_init(&out);
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_hd_inflate_init(&inflater, mem);
|
2013-07-19 09:50:31 +02:00
|
|
|
|
2015-04-14 18:21:27 +02:00
|
|
|
CU_ASSERT(
|
|
|
|
0 == nghttp2_hd_emit_newname_block(&bufs, &nv, NGHTTP2_HD_WITH_INDEXING));
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
|
|
|
CU_ASSERT(blocklen > 0);
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2014-01-16 15:41:13 +01:00
|
|
|
|
|
|
|
CU_ASSERT(1 == out.nvlen);
|
2015-03-03 15:23:43 +01:00
|
|
|
assert_nv_equal(&nv, out.nva, 1, mem);
|
2014-01-26 09:53:04 +01:00
|
|
|
CU_ASSERT(1 == inflater.ctx.hd_table.len);
|
2015-10-21 17:57:00 +02:00
|
|
|
assert_nv_equal(&nv,
|
|
|
|
&nghttp2_hd_table_get(&inflater.ctx,
|
|
|
|
NGHTTP2_STATIC_TABLE_LENGTH +
|
|
|
|
inflater.ctx.hd_table.len - 1)->nv,
|
|
|
|
1, mem);
|
2013-07-19 09:50:31 +02:00
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_free(&bufs);
|
2013-07-19 09:50:31 +02:00
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
|
|
|
}
|
2013-07-27 11:59:30 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void test_nghttp2_hd_inflate_clearall_inc(void) {
|
2014-01-26 09:53:04 +01:00
|
|
|
nghttp2_hd_inflater inflater;
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs bufs;
|
2014-03-10 17:47:38 +01:00
|
|
|
ssize_t blocklen;
|
2013-08-28 16:16:23 +02:00
|
|
|
nghttp2_nv nv;
|
2015-03-23 15:25:57 +01:00
|
|
|
uint8_t value[4061];
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out out;
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem *mem;
|
2013-08-28 16:16:23 +02:00
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
mem = nghttp2_mem_default();
|
2014-03-13 14:11:02 +01:00
|
|
|
bufs_large_init(&bufs, 8192);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out_init(&out);
|
2013-08-28 16:16:23 +02:00
|
|
|
/* Total 4097 bytes space required to hold this entry */
|
2014-11-27 15:39:04 +01:00
|
|
|
nv.name = (uint8_t *)"alpha";
|
|
|
|
nv.namelen = strlen((char *)nv.name);
|
2013-08-28 16:16:23 +02:00
|
|
|
memset(value, '0', sizeof(value));
|
2015-03-23 15:25:57 +01:00
|
|
|
value[sizeof(value) - 1] = '\0';
|
2013-08-28 16:16:23 +02:00
|
|
|
nv.value = value;
|
2015-03-23 15:25:57 +01:00
|
|
|
nv.valuelen = sizeof(value) - 1;
|
2013-08-28 16:16:23 +02:00
|
|
|
|
2014-04-01 18:25:44 +02:00
|
|
|
nv.flags = NGHTTP2_NV_FLAG_NONE;
|
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_hd_inflate_init(&inflater, mem);
|
2013-08-28 16:16:23 +02:00
|
|
|
|
2015-04-14 18:21:27 +02:00
|
|
|
CU_ASSERT(
|
|
|
|
0 == nghttp2_hd_emit_newname_block(&bufs, &nv, NGHTTP2_HD_WITH_INDEXING));
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
|
|
|
CU_ASSERT(blocklen > 0);
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2014-01-16 15:41:13 +01:00
|
|
|
|
|
|
|
CU_ASSERT(1 == out.nvlen);
|
2015-03-03 15:23:43 +01:00
|
|
|
assert_nv_equal(&nv, out.nva, 1, mem);
|
2014-01-26 09:53:04 +01:00
|
|
|
CU_ASSERT(0 == inflater.ctx.hd_table.len);
|
2013-08-28 16:16:23 +02:00
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2013-08-28 16:16:23 +02:00
|
|
|
|
|
|
|
/* Do it again */
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2014-01-16 15:41:13 +01:00
|
|
|
|
|
|
|
CU_ASSERT(1 == out.nvlen);
|
2015-03-03 15:23:43 +01:00
|
|
|
assert_nv_equal(&nv, out.nva, 1, mem);
|
2014-01-26 09:53:04 +01:00
|
|
|
CU_ASSERT(0 == inflater.ctx.hd_table.len);
|
2013-08-28 16:16:23 +02:00
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
2013-08-28 16:16:23 +02:00
|
|
|
|
|
|
|
/* This time, 4096 bytes space required, which is just fits in the
|
|
|
|
header table */
|
2015-03-23 15:25:57 +01:00
|
|
|
nv.valuelen = sizeof(value) - 2;
|
2013-08-28 16:16:23 +02:00
|
|
|
|
2015-04-14 18:21:27 +02:00
|
|
|
CU_ASSERT(
|
|
|
|
0 == nghttp2_hd_emit_newname_block(&bufs, &nv, NGHTTP2_HD_WITH_INDEXING));
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
|
|
|
CU_ASSERT(blocklen > 0);
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2014-01-16 15:41:13 +01:00
|
|
|
|
|
|
|
CU_ASSERT(1 == out.nvlen);
|
2015-03-03 15:23:43 +01:00
|
|
|
assert_nv_equal(&nv, out.nva, 1, mem);
|
2014-01-26 09:53:04 +01:00
|
|
|
CU_ASSERT(1 == inflater.ctx.hd_table.len);
|
2013-08-28 16:16:23 +02:00
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
2013-08-28 16:16:23 +02:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_free(&bufs);
|
2013-08-28 16:16:23 +02:00
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void test_nghttp2_hd_inflate_zero_length_huffman(void) {
|
2014-01-26 09:53:04 +01:00
|
|
|
nghttp2_hd_inflater inflater;
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs bufs;
|
|
|
|
/* Literal header without indexing - new name */
|
2014-11-27 15:39:04 +01:00
|
|
|
uint8_t data[] = {0x40, 0x01, 0x78 /* 'x' */, 0x80};
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out out;
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem *mem;
|
2013-12-19 15:19:14 +01:00
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
mem = nghttp2_mem_default();
|
2014-03-13 14:11:02 +01:00
|
|
|
frame_pack_bufs_init(&bufs);
|
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out_init(&out);
|
2014-03-13 14:11:02 +01:00
|
|
|
|
|
|
|
nghttp2_bufs_add(&bufs, data, sizeof(data));
|
|
|
|
|
|
|
|
/* /\* Literal header without indexing - new name *\/ */
|
|
|
|
/* ptr[0] = 0x40; */
|
|
|
|
/* ptr[1] = 1; */
|
|
|
|
/* ptr[2] = 'x'; */
|
|
|
|
/* ptr[3] = 0x80; */
|
2013-12-19 15:19:14 +01:00
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_hd_inflate_init(&inflater, mem);
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(4 == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2013-12-19 15:19:14 +01:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
CU_ASSERT(1 == out.nvlen);
|
|
|
|
CU_ASSERT(1 == out.nva[0].namelen);
|
|
|
|
CU_ASSERT('x' == out.nva[0].name[0]);
|
|
|
|
CU_ASSERT(NULL == out.nva[0].value);
|
|
|
|
CU_ASSERT(0 == out.nva[0].valuelen);
|
2013-12-19 15:19:14 +01:00
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_free(&bufs);
|
2013-12-19 15:19:14 +01:00
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
|
|
|
}
|
|
|
|
|
2015-07-21 17:11:23 +02:00
|
|
|
void test_nghttp2_hd_inflate_expect_table_size_update(void) {
|
|
|
|
nghttp2_hd_inflater inflater;
|
|
|
|
nghttp2_bufs bufs;
|
|
|
|
nghttp2_mem *mem;
|
|
|
|
/* Indexed Header: :method: GET */
|
|
|
|
uint8_t data[] = {0x82};
|
|
|
|
nva_out out;
|
|
|
|
|
|
|
|
mem = nghttp2_mem_default();
|
|
|
|
frame_pack_bufs_init(&bufs);
|
|
|
|
nva_out_init(&out);
|
|
|
|
|
|
|
|
nghttp2_bufs_add(&bufs, data, sizeof(data));
|
|
|
|
nghttp2_hd_inflate_init(&inflater, mem);
|
|
|
|
/* This will make inflater require table size update in the next
|
|
|
|
inflation. */
|
2015-10-24 10:27:24 +02:00
|
|
|
nghttp2_hd_inflate_change_table_size(&inflater, 4095);
|
2015-07-21 17:11:23 +02:00
|
|
|
nghttp2_hd_inflate_change_table_size(&inflater, 4096);
|
|
|
|
CU_ASSERT(NGHTTP2_ERR_HEADER_COMP ==
|
|
|
|
inflate_hd(&inflater, &out, &bufs, 0, mem));
|
|
|
|
|
|
|
|
nva_out_reset(&out, mem);
|
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
2015-10-24 10:27:24 +02:00
|
|
|
|
|
|
|
/* This does not require for encoder to emit table size update since
|
|
|
|
* size is not changed. */
|
|
|
|
nghttp2_hd_inflate_init(&inflater, mem);
|
|
|
|
nghttp2_hd_inflate_change_table_size(&inflater, 4096);
|
|
|
|
CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) ==
|
|
|
|
inflate_hd(&inflater, &out, &bufs, 0, mem));
|
|
|
|
|
|
|
|
nva_out_reset(&out, mem);
|
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
|
|
|
|
|
|
|
/* This does not require for encodre to emit table size update since
|
|
|
|
new size is larger than current size. */
|
|
|
|
nghttp2_hd_inflate_init(&inflater, mem);
|
|
|
|
nghttp2_hd_inflate_change_table_size(&inflater, 4097);
|
|
|
|
CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) ==
|
|
|
|
inflate_hd(&inflater, &out, &bufs, 0, mem));
|
|
|
|
|
|
|
|
nva_out_reset(&out, mem);
|
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
|
|
|
|
|
|
|
/* Received table size is strictly larger than minimum table size */
|
|
|
|
nghttp2_hd_inflate_init(&inflater, mem);
|
|
|
|
nghttp2_hd_inflate_change_table_size(&inflater, 111);
|
|
|
|
nghttp2_hd_inflate_change_table_size(&inflater, 4096);
|
|
|
|
|
|
|
|
nghttp2_bufs_reset(&bufs);
|
|
|
|
nghttp2_hd_emit_table_size(&bufs, 112);
|
|
|
|
|
|
|
|
CU_ASSERT(NGHTTP2_ERR_HEADER_COMP ==
|
|
|
|
inflate_hd(&inflater, &out, &bufs, 0, mem));
|
|
|
|
|
|
|
|
nva_out_reset(&out, mem);
|
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
|
|
|
|
|
|
|
/* Receiving 2 table size updates, min and last value */
|
|
|
|
nghttp2_hd_inflate_init(&inflater, mem);
|
|
|
|
nghttp2_hd_inflate_change_table_size(&inflater, 111);
|
|
|
|
nghttp2_hd_inflate_change_table_size(&inflater, 4096);
|
|
|
|
|
|
|
|
nghttp2_bufs_reset(&bufs);
|
|
|
|
nghttp2_hd_emit_table_size(&bufs, 111);
|
|
|
|
nghttp2_hd_emit_table_size(&bufs, 4096);
|
|
|
|
|
|
|
|
CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) ==
|
|
|
|
inflate_hd(&inflater, &out, &bufs, 0, mem));
|
|
|
|
|
|
|
|
nva_out_reset(&out, mem);
|
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
|
|
|
|
|
|
|
/* 2nd update is larger than last value */
|
|
|
|
nghttp2_hd_inflate_init(&inflater, mem);
|
|
|
|
nghttp2_hd_inflate_change_table_size(&inflater, 111);
|
|
|
|
nghttp2_hd_inflate_change_table_size(&inflater, 4095);
|
|
|
|
|
|
|
|
nghttp2_bufs_reset(&bufs);
|
|
|
|
nghttp2_hd_emit_table_size(&bufs, 111);
|
|
|
|
nghttp2_hd_emit_table_size(&bufs, 4096);
|
|
|
|
|
|
|
|
CU_ASSERT(NGHTTP2_ERR_HEADER_COMP ==
|
|
|
|
inflate_hd(&inflater, &out, &bufs, 0, mem));
|
|
|
|
|
|
|
|
nva_out_reset(&out, mem);
|
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
|
|
|
|
|
|
|
nghttp2_bufs_free(&bufs);
|
2015-07-21 17:11:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_nghttp2_hd_inflate_unexpected_table_size_update(void) {
|
|
|
|
nghttp2_hd_inflater inflater;
|
|
|
|
nghttp2_bufs bufs;
|
|
|
|
nghttp2_mem *mem;
|
|
|
|
/* Indexed Header: :method: GET, followed by table size update.
|
|
|
|
This violates RFC 7541. */
|
|
|
|
uint8_t data[] = {0x82, 0x20};
|
|
|
|
nva_out out;
|
|
|
|
|
|
|
|
mem = nghttp2_mem_default();
|
|
|
|
frame_pack_bufs_init(&bufs);
|
|
|
|
nva_out_init(&out);
|
|
|
|
|
|
|
|
nghttp2_bufs_add(&bufs, data, sizeof(data));
|
|
|
|
nghttp2_hd_inflate_init(&inflater, mem);
|
|
|
|
CU_ASSERT(NGHTTP2_ERR_HEADER_COMP ==
|
|
|
|
inflate_hd(&inflater, &out, &bufs, 0, mem));
|
|
|
|
|
|
|
|
nva_out_reset(&out, mem);
|
|
|
|
nghttp2_bufs_free(&bufs);
|
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void test_nghttp2_hd_ringbuf_reserve(void) {
|
2014-06-22 06:39:17 +02:00
|
|
|
nghttp2_hd_deflater deflater;
|
|
|
|
nghttp2_hd_inflater inflater;
|
|
|
|
nghttp2_nv nv;
|
|
|
|
nghttp2_bufs bufs;
|
|
|
|
nva_out out;
|
|
|
|
int i;
|
|
|
|
ssize_t rv;
|
|
|
|
ssize_t blocklen;
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem *mem;
|
2014-06-22 06:39:17 +02:00
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
mem = nghttp2_mem_default();
|
2014-06-22 06:39:17 +02:00
|
|
|
frame_pack_bufs_init(&bufs);
|
|
|
|
nva_out_init(&out);
|
|
|
|
|
|
|
|
nv.flags = NGHTTP2_NV_FLAG_NONE;
|
2014-11-27 15:39:04 +01:00
|
|
|
nv.name = (uint8_t *)"a";
|
|
|
|
nv.namelen = strlen((const char *)nv.name);
|
2014-06-22 06:39:17 +02:00
|
|
|
nv.valuelen = 4;
|
2015-03-23 15:25:57 +01:00
|
|
|
nv.value = mem->malloc(nv.valuelen + 1, NULL);
|
2014-06-22 06:39:17 +02:00
|
|
|
memset(nv.value, 0, nv.valuelen);
|
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_hd_deflate_init2(&deflater, 8000, mem);
|
|
|
|
nghttp2_hd_inflate_init(&inflater, mem);
|
2014-06-22 06:39:17 +02:00
|
|
|
|
|
|
|
nghttp2_hd_inflate_change_table_size(&inflater, 8000);
|
|
|
|
nghttp2_hd_deflate_change_table_size(&deflater, 8000);
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
for (i = 0; i < 150; ++i) {
|
2014-06-22 06:39:17 +02:00
|
|
|
memcpy(nv.value, &i, sizeof(i));
|
|
|
|
rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, &nv, 1);
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-06-22 06:39:17 +02:00
|
|
|
|
|
|
|
CU_ASSERT(0 == rv);
|
|
|
|
CU_ASSERT(blocklen > 0);
|
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2014-06-22 06:39:17 +02:00
|
|
|
|
|
|
|
CU_ASSERT(1 == out.nvlen);
|
2015-03-03 15:23:43 +01:00
|
|
|
assert_nv_equal(&nv, out.nva, 1, mem);
|
2014-06-22 06:39:17 +02:00
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-06-22 06:39:17 +02:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
|
|
|
}
|
|
|
|
|
|
|
|
nghttp2_bufs_free(&bufs);
|
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
|
|
|
nghttp2_hd_deflate_free(&deflater);
|
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
mem->free(nv.value, NULL);
|
2014-06-22 06:39:17 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void test_nghttp2_hd_change_table_size(void) {
|
2014-01-26 09:53:04 +01:00
|
|
|
nghttp2_hd_deflater deflater;
|
2014-02-13 15:22:52 +01:00
|
|
|
nghttp2_hd_inflater inflater;
|
2014-11-27 15:39:04 +01:00
|
|
|
nghttp2_nv nva[] = {MAKE_NV("alpha", "bravo"), MAKE_NV("charlie", "delta")};
|
|
|
|
nghttp2_nv nva2[] = {MAKE_NV(":path", "/")};
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs bufs;
|
2013-10-25 18:01:28 +02:00
|
|
|
ssize_t rv;
|
2014-02-13 15:22:52 +01:00
|
|
|
nva_out out;
|
2014-03-13 14:11:02 +01:00
|
|
|
ssize_t blocklen;
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem *mem;
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
mem = nghttp2_mem_default();
|
2014-03-13 14:11:02 +01:00
|
|
|
frame_pack_bufs_init(&bufs);
|
2013-10-25 18:01:28 +02:00
|
|
|
|
2014-02-13 15:22:52 +01:00
|
|
|
nva_out_init(&out);
|
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_hd_deflate_init(&deflater, mem);
|
|
|
|
nghttp2_hd_inflate_init(&inflater, mem);
|
2014-02-13 15:22:52 +01:00
|
|
|
|
|
|
|
/* inflater changes notifies 8000 max header table size */
|
|
|
|
CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, 8000));
|
|
|
|
CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, 8000));
|
|
|
|
|
2014-05-11 14:25:27 +02:00
|
|
|
CU_ASSERT(4096 == deflater.ctx.hd_table_bufsize_max);
|
2013-10-25 18:01:28 +02:00
|
|
|
|
2014-02-13 15:22:52 +01:00
|
|
|
CU_ASSERT(8000 == inflater.ctx.hd_table_bufsize_max);
|
|
|
|
CU_ASSERT(8000 == inflater.settings_hd_table_bufsize_max);
|
|
|
|
|
|
|
|
/* This will emit encoding context update with header table size 4096 */
|
2014-05-13 16:42:55 +02:00
|
|
|
rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, 2);
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-03-13 14:11:02 +01:00
|
|
|
|
|
|
|
CU_ASSERT(0 == rv);
|
|
|
|
CU_ASSERT(blocklen > 0);
|
2014-01-26 09:53:04 +01:00
|
|
|
CU_ASSERT(2 == deflater.ctx.hd_table.len);
|
2015-10-21 17:57:00 +02:00
|
|
|
CU_ASSERT(63 == nghttp2_hd_deflate_get_num_table_entries(&deflater));
|
2014-02-13 15:22:52 +01:00
|
|
|
CU_ASSERT(4096 == deflater.ctx.hd_table_bufsize_max);
|
2013-10-25 18:01:28 +02:00
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2014-02-13 15:22:52 +01:00
|
|
|
CU_ASSERT(2 == inflater.ctx.hd_table.len);
|
2015-10-21 17:57:00 +02:00
|
|
|
CU_ASSERT(63 == nghttp2_hd_inflate_get_num_table_entries(&inflater));
|
2014-02-13 15:22:52 +01:00
|
|
|
CU_ASSERT(4096 == inflater.ctx.hd_table_bufsize_max);
|
|
|
|
CU_ASSERT(8000 == inflater.settings_hd_table_bufsize_max);
|
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
2014-02-13 15:22:52 +01:00
|
|
|
|
|
|
|
/* inflater changes header table size to 1024 */
|
|
|
|
CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, 1024));
|
|
|
|
CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, 1024));
|
|
|
|
|
|
|
|
CU_ASSERT(1024 == deflater.ctx.hd_table_bufsize_max);
|
|
|
|
|
|
|
|
CU_ASSERT(1024 == inflater.ctx.hd_table_bufsize_max);
|
|
|
|
CU_ASSERT(1024 == inflater.settings_hd_table_bufsize_max);
|
|
|
|
|
2014-05-13 16:42:55 +02:00
|
|
|
rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, 2);
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-03-13 14:11:02 +01:00
|
|
|
|
|
|
|
CU_ASSERT(0 == rv);
|
2014-05-11 14:25:27 +02:00
|
|
|
CU_ASSERT(blocklen > 0);
|
2014-01-26 09:53:04 +01:00
|
|
|
CU_ASSERT(2 == deflater.ctx.hd_table.len);
|
2015-10-21 17:57:00 +02:00
|
|
|
CU_ASSERT(63 == nghttp2_hd_deflate_get_num_table_entries(&deflater));
|
2014-02-13 15:22:52 +01:00
|
|
|
CU_ASSERT(1024 == deflater.ctx.hd_table_bufsize_max);
|
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2014-02-13 15:22:52 +01:00
|
|
|
CU_ASSERT(2 == inflater.ctx.hd_table.len);
|
2015-10-21 17:57:00 +02:00
|
|
|
CU_ASSERT(63 == nghttp2_hd_inflate_get_num_table_entries(&inflater));
|
2014-02-13 15:22:52 +01:00
|
|
|
CU_ASSERT(1024 == inflater.ctx.hd_table_bufsize_max);
|
|
|
|
CU_ASSERT(1024 == inflater.settings_hd_table_bufsize_max);
|
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
2014-02-13 15:22:52 +01:00
|
|
|
|
|
|
|
/* inflater changes header table size to 0 */
|
|
|
|
CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, 0));
|
|
|
|
CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, 0));
|
|
|
|
|
|
|
|
CU_ASSERT(0 == deflater.ctx.hd_table.len);
|
2015-10-21 17:57:00 +02:00
|
|
|
CU_ASSERT(61 == nghttp2_hd_deflate_get_num_table_entries(&deflater));
|
2014-02-13 15:22:52 +01:00
|
|
|
CU_ASSERT(0 == deflater.ctx.hd_table_bufsize_max);
|
2013-10-25 18:01:28 +02:00
|
|
|
|
2014-02-13 15:22:52 +01:00
|
|
|
CU_ASSERT(0 == inflater.ctx.hd_table.len);
|
2015-10-21 17:57:00 +02:00
|
|
|
CU_ASSERT(61 == nghttp2_hd_inflate_get_num_table_entries(&inflater));
|
2014-02-13 15:22:52 +01:00
|
|
|
CU_ASSERT(0 == inflater.ctx.hd_table_bufsize_max);
|
|
|
|
CU_ASSERT(0 == inflater.settings_hd_table_bufsize_max);
|
|
|
|
|
2014-05-13 16:42:55 +02:00
|
|
|
rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, 2);
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-03-13 14:11:02 +01:00
|
|
|
|
|
|
|
CU_ASSERT(0 == rv);
|
|
|
|
CU_ASSERT(blocklen > 0);
|
2014-01-26 09:53:04 +01:00
|
|
|
CU_ASSERT(0 == deflater.ctx.hd_table.len);
|
2015-10-21 17:57:00 +02:00
|
|
|
CU_ASSERT(61 == nghttp2_hd_deflate_get_num_table_entries(&deflater));
|
2014-02-13 15:22:52 +01:00
|
|
|
CU_ASSERT(0 == deflater.ctx.hd_table_bufsize_max);
|
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2014-02-13 15:22:52 +01:00
|
|
|
CU_ASSERT(0 == inflater.ctx.hd_table.len);
|
2015-10-21 17:57:00 +02:00
|
|
|
CU_ASSERT(61 == nghttp2_hd_inflate_get_num_table_entries(&inflater));
|
2014-02-13 15:22:52 +01:00
|
|
|
CU_ASSERT(0 == inflater.ctx.hd_table_bufsize_max);
|
|
|
|
CU_ASSERT(0 == inflater.settings_hd_table_bufsize_max);
|
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
2013-10-25 18:01:28 +02:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_free(&bufs);
|
2014-02-13 15:22:52 +01:00
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
|
|
|
nghttp2_hd_deflate_free(&deflater);
|
|
|
|
|
|
|
|
/* Check table buffer is expanded */
|
2014-03-13 14:11:02 +01:00
|
|
|
frame_pack_bufs_init(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_hd_deflate_init2(&deflater, 8192, mem);
|
|
|
|
nghttp2_hd_inflate_init(&inflater, mem);
|
2014-02-13 15:22:52 +01:00
|
|
|
|
|
|
|
/* First inflater changes header table size to 8000 */
|
|
|
|
CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, 8000));
|
|
|
|
CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, 8000));
|
|
|
|
|
|
|
|
CU_ASSERT(8000 == deflater.ctx.hd_table_bufsize_max);
|
2015-10-21 17:57:00 +02:00
|
|
|
CU_ASSERT(8000 == nghttp2_hd_deflate_get_max_dynamic_table_size(&deflater));
|
2014-02-13 15:22:52 +01:00
|
|
|
CU_ASSERT(8000 == inflater.ctx.hd_table_bufsize_max);
|
2015-10-21 17:57:00 +02:00
|
|
|
CU_ASSERT(8000 == nghttp2_hd_inflate_get_max_dynamic_table_size(&inflater));
|
2014-02-13 15:22:52 +01:00
|
|
|
CU_ASSERT(8000 == inflater.settings_hd_table_bufsize_max);
|
|
|
|
|
2014-05-13 16:42:55 +02:00
|
|
|
rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, 2);
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-03-13 14:11:02 +01:00
|
|
|
|
|
|
|
CU_ASSERT(0 == rv);
|
|
|
|
CU_ASSERT(blocklen > 0);
|
2014-02-13 15:22:52 +01:00
|
|
|
CU_ASSERT(2 == deflater.ctx.hd_table.len);
|
|
|
|
CU_ASSERT(8000 == deflater.ctx.hd_table_bufsize_max);
|
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2014-02-13 15:22:52 +01:00
|
|
|
CU_ASSERT(2 == inflater.ctx.hd_table.len);
|
|
|
|
CU_ASSERT(8000 == inflater.ctx.hd_table_bufsize_max);
|
|
|
|
CU_ASSERT(8000 == inflater.settings_hd_table_bufsize_max);
|
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
2014-02-13 15:22:52 +01:00
|
|
|
|
|
|
|
CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, 16383));
|
|
|
|
CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, 16383));
|
|
|
|
|
2014-05-11 14:25:27 +02:00
|
|
|
CU_ASSERT(8192 == deflater.ctx.hd_table_bufsize_max);
|
2015-10-21 17:57:00 +02:00
|
|
|
CU_ASSERT(8192 == nghttp2_hd_deflate_get_max_dynamic_table_size(&deflater));
|
2014-02-13 15:22:52 +01:00
|
|
|
|
|
|
|
CU_ASSERT(16383 == inflater.ctx.hd_table_bufsize_max);
|
2015-10-21 17:57:00 +02:00
|
|
|
CU_ASSERT(16383 == nghttp2_hd_inflate_get_max_dynamic_table_size(&inflater));
|
2014-02-13 15:22:52 +01:00
|
|
|
CU_ASSERT(16383 == inflater.settings_hd_table_bufsize_max);
|
|
|
|
|
2014-05-13 16:42:55 +02:00
|
|
|
rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, 2);
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-03-13 14:11:02 +01:00
|
|
|
|
|
|
|
CU_ASSERT(0 == rv);
|
|
|
|
CU_ASSERT(blocklen > 0);
|
2014-02-13 15:22:52 +01:00
|
|
|
CU_ASSERT(2 == deflater.ctx.hd_table.len);
|
|
|
|
CU_ASSERT(8192 == deflater.ctx.hd_table_bufsize_max);
|
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2014-02-13 15:22:52 +01:00
|
|
|
CU_ASSERT(2 == inflater.ctx.hd_table.len);
|
|
|
|
CU_ASSERT(8192 == inflater.ctx.hd_table_bufsize_max);
|
|
|
|
CU_ASSERT(16383 == inflater.settings_hd_table_bufsize_max);
|
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
2014-02-13 15:22:52 +01:00
|
|
|
|
|
|
|
/* Lastly, check the error condition */
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
rv = nghttp2_hd_emit_table_size(&bufs, 25600);
|
2014-02-13 15:22:52 +01:00
|
|
|
CU_ASSERT(rv == 0);
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(NGHTTP2_ERR_HEADER_COMP ==
|
|
|
|
inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2014-02-13 15:22:52 +01:00
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
2014-02-13 15:22:52 +01:00
|
|
|
|
2014-02-21 13:18:46 +01:00
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
|
|
|
nghttp2_hd_deflate_free(&deflater);
|
|
|
|
|
|
|
|
/* Check that encoder can handle the case where its allowable buffer
|
|
|
|
size is less than default size, 4096 */
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_hd_deflate_init2(&deflater, 1024, mem);
|
|
|
|
nghttp2_hd_inflate_init(&inflater, mem);
|
2014-02-21 13:18:46 +01:00
|
|
|
|
2014-05-11 14:25:27 +02:00
|
|
|
CU_ASSERT(1024 == deflater.ctx.hd_table_bufsize_max);
|
2014-02-21 13:18:46 +01:00
|
|
|
|
|
|
|
/* This emits context update with buffer size 1024 */
|
2014-05-13 16:42:55 +02:00
|
|
|
rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, 2);
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-03-13 14:11:02 +01:00
|
|
|
|
|
|
|
CU_ASSERT(0 == rv);
|
|
|
|
CU_ASSERT(blocklen > 0);
|
2014-02-21 13:18:46 +01:00
|
|
|
CU_ASSERT(2 == deflater.ctx.hd_table.len);
|
|
|
|
CU_ASSERT(1024 == deflater.ctx.hd_table_bufsize_max);
|
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2014-02-21 13:18:46 +01:00
|
|
|
CU_ASSERT(2 == inflater.ctx.hd_table.len);
|
|
|
|
CU_ASSERT(1024 == inflater.ctx.hd_table_bufsize_max);
|
|
|
|
CU_ASSERT(4096 == inflater.settings_hd_table_bufsize_max);
|
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
2014-02-27 19:07:19 +01:00
|
|
|
|
2014-02-13 15:22:52 +01:00
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
2013-10-25 18:01:28 +02:00
|
|
|
nghttp2_hd_deflate_free(&deflater);
|
2014-07-22 15:38:18 +02:00
|
|
|
|
|
|
|
/* Check that table size UINT32_MAX can be received */
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_hd_deflate_init2(&deflater, UINT32_MAX, mem);
|
|
|
|
nghttp2_hd_inflate_init(&inflater, mem);
|
2014-07-22 15:38:18 +02:00
|
|
|
|
|
|
|
CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, UINT32_MAX));
|
|
|
|
CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, UINT32_MAX));
|
|
|
|
|
|
|
|
rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, 2);
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-07-22 15:38:18 +02:00
|
|
|
|
|
|
|
CU_ASSERT(0 == rv);
|
|
|
|
CU_ASSERT(UINT32_MAX == deflater.ctx.hd_table_bufsize_max);
|
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2014-07-22 15:38:18 +02:00
|
|
|
CU_ASSERT(UINT32_MAX == inflater.ctx.hd_table_bufsize_max);
|
|
|
|
CU_ASSERT(UINT32_MAX == inflater.settings_hd_table_bufsize_max);
|
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-07-22 15:38:18 +02:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
|
|
|
|
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
2014-07-25 15:55:45 +02:00
|
|
|
nghttp2_hd_deflate_free(&deflater);
|
|
|
|
|
|
|
|
/* Check that context update emitted twice */
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_hd_deflate_init2(&deflater, 4096, mem);
|
|
|
|
nghttp2_hd_inflate_init(&inflater, mem);
|
2014-07-25 15:55:45 +02:00
|
|
|
|
|
|
|
CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, 0));
|
|
|
|
CU_ASSERT(0 == nghttp2_hd_inflate_change_table_size(&inflater, 3000));
|
|
|
|
CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, 0));
|
|
|
|
CU_ASSERT(0 == nghttp2_hd_deflate_change_table_size(&deflater, 3000));
|
|
|
|
|
|
|
|
CU_ASSERT(0 == deflater.min_hd_table_bufsize_max);
|
|
|
|
CU_ASSERT(3000 == deflater.ctx.hd_table_bufsize_max);
|
|
|
|
|
|
|
|
rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva2, 1);
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-07-25 15:55:45 +02:00
|
|
|
|
|
|
|
CU_ASSERT(0 == rv);
|
|
|
|
CU_ASSERT(3 < blocklen);
|
|
|
|
CU_ASSERT(3000 == deflater.ctx.hd_table_bufsize_max);
|
|
|
|
CU_ASSERT(UINT32_MAX == deflater.min_hd_table_bufsize_max);
|
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2014-07-25 15:55:45 +02:00
|
|
|
CU_ASSERT(3000 == inflater.ctx.hd_table_bufsize_max);
|
|
|
|
CU_ASSERT(3000 == inflater.settings_hd_table_bufsize_max);
|
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-07-25 15:55:45 +02:00
|
|
|
nghttp2_bufs_reset(&bufs);
|
|
|
|
|
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
2014-07-22 15:38:18 +02:00
|
|
|
nghttp2_hd_deflate_free(&deflater);
|
|
|
|
|
|
|
|
nghttp2_bufs_free(&bufs);
|
2013-10-25 18:01:28 +02:00
|
|
|
}
|
|
|
|
|
2014-01-26 09:53:04 +01:00
|
|
|
static void check_deflate_inflate(nghttp2_hd_deflater *deflater,
|
|
|
|
nghttp2_hd_inflater *inflater,
|
2015-03-03 15:23:43 +01:00
|
|
|
nghttp2_nv *nva, size_t nvlen,
|
|
|
|
nghttp2_mem *mem) {
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs bufs;
|
2013-07-27 11:59:30 +02:00
|
|
|
ssize_t blocklen;
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out out;
|
2014-03-13 14:11:02 +01:00
|
|
|
int rv;
|
2013-07-27 11:59:30 +02:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
frame_pack_bufs_init(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-01-16 15:41:13 +01:00
|
|
|
nva_out_init(&out);
|
2014-05-13 16:42:55 +02:00
|
|
|
rv = nghttp2_hd_deflate_hd_bufs(deflater, &bufs, nva, nvlen);
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-03-10 17:47:38 +01:00
|
|
|
|
2014-03-13 14:11:02 +01:00
|
|
|
CU_ASSERT(0 == rv);
|
2014-03-10 17:47:38 +01:00
|
|
|
CU_ASSERT(blocklen >= 0);
|
2013-07-28 12:08:49 +02:00
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(inflater, &out, &bufs, 0, mem));
|
2014-01-16 15:41:13 +01:00
|
|
|
|
|
|
|
CU_ASSERT(nvlen == out.nvlen);
|
2015-03-03 15:23:43 +01:00
|
|
|
assert_nv_equal(nva, out.nva, nvlen, mem);
|
2014-01-16 15:41:13 +01:00
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-03-13 14:11:02 +01:00
|
|
|
nghttp2_bufs_free(&bufs);
|
2013-07-27 11:59:30 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void test_nghttp2_hd_deflate_inflate(void) {
|
2014-01-26 09:53:04 +01:00
|
|
|
nghttp2_hd_deflater deflater;
|
|
|
|
nghttp2_hd_inflater inflater;
|
2013-07-27 11:59:30 +02:00
|
|
|
nghttp2_nv nv1[] = {
|
2015-11-12 16:53:29 +01:00
|
|
|
MAKE_NV(":status", "200 OK"), MAKE_NV("access-control-allow-origin", "*"),
|
2014-11-27 15:39:04 +01:00
|
|
|
MAKE_NV("cache-control", "private, max-age=0, must-revalidate"),
|
2015-11-12 16:53:29 +01:00
|
|
|
MAKE_NV("content-length", "76073"), MAKE_NV("content-type", "text/html"),
|
2014-11-27 15:39:04 +01:00
|
|
|
MAKE_NV("date", "Sat, 27 Jul 2013 06:22:12 GMT"),
|
|
|
|
MAKE_NV("expires", "Sat, 27 Jul 2013 06:22:12 GMT"),
|
2015-11-12 16:53:29 +01:00
|
|
|
MAKE_NV("server", "Apache"), MAKE_NV("vary", "foobar"),
|
2014-11-27 15:39:04 +01:00
|
|
|
MAKE_NV("via", "1.1 alphabravo (squid/3.x.x), 1.1 nghttpx"),
|
|
|
|
MAKE_NV("x-cache", "MISS from alphabravo"),
|
2015-11-12 16:53:29 +01:00
|
|
|
MAKE_NV("x-cache-action", "MISS"), MAKE_NV("x-cache-age", "0"),
|
2014-11-27 15:39:04 +01:00
|
|
|
MAKE_NV("x-cache-lookup", "MISS from alphabravo:3128"),
|
|
|
|
MAKE_NV("x-lb-nocache", "true"),
|
2013-07-27 11:59:30 +02:00
|
|
|
};
|
|
|
|
nghttp2_nv nv2[] = {
|
2015-11-12 16:53:29 +01:00
|
|
|
MAKE_NV(":status", "304 Not Modified"), MAKE_NV("age", "0"),
|
2014-11-27 15:39:04 +01:00
|
|
|
MAKE_NV("cache-control", "max-age=56682045"),
|
|
|
|
MAKE_NV("content-type", "text/css"),
|
|
|
|
MAKE_NV("date", "Sat, 27 Jul 2013 06:22:12 GMT"),
|
|
|
|
MAKE_NV("expires", "Thu, 14 May 2015 07:22:57 GMT"),
|
|
|
|
MAKE_NV("last-modified", "Tue, 14 May 2013 07:22:15 GMT"),
|
|
|
|
MAKE_NV("vary", "Accept-Encoding"),
|
|
|
|
MAKE_NV("via", "1.1 alphabravo (squid/3.x.x), 1.1 nghttpx"),
|
|
|
|
MAKE_NV("x-cache", "HIT from alphabravo"),
|
|
|
|
MAKE_NV("x-cache-lookup", "HIT from alphabravo:3128")};
|
2013-07-27 11:59:30 +02:00
|
|
|
nghttp2_nv nv3[] = {
|
2015-11-12 16:53:29 +01:00
|
|
|
MAKE_NV(":status", "304 Not Modified"), MAKE_NV("age", "0"),
|
2014-11-27 15:39:04 +01:00
|
|
|
MAKE_NV("cache-control", "max-age=56682072"),
|
|
|
|
MAKE_NV("content-type", "text/css"),
|
|
|
|
MAKE_NV("date", "Sat, 27 Jul 2013 06:22:12 GMT"),
|
|
|
|
MAKE_NV("expires", "Thu, 14 May 2015 07:23:24 GMT"),
|
|
|
|
MAKE_NV("last-modified", "Tue, 14 May 2013 07:22:13 GMT"),
|
|
|
|
MAKE_NV("vary", "Accept-Encoding"),
|
|
|
|
MAKE_NV("via", "1.1 alphabravo (squid/3.x.x), 1.1 nghttpx"),
|
|
|
|
MAKE_NV("x-cache", "HIT from alphabravo"),
|
|
|
|
MAKE_NV("x-cache-lookup", "HIT from alphabravo:3128"),
|
2013-07-27 11:59:30 +02:00
|
|
|
};
|
|
|
|
nghttp2_nv nv4[] = {
|
2015-11-12 16:53:29 +01:00
|
|
|
MAKE_NV(":status", "304 Not Modified"), MAKE_NV("age", "0"),
|
2014-11-27 15:39:04 +01:00
|
|
|
MAKE_NV("cache-control", "max-age=56682022"),
|
|
|
|
MAKE_NV("content-type", "text/css"),
|
|
|
|
MAKE_NV("date", "Sat, 27 Jul 2013 06:22:12 GMT"),
|
|
|
|
MAKE_NV("expires", "Thu, 14 May 2015 07:22:34 GMT"),
|
|
|
|
MAKE_NV("last-modified", "Tue, 14 May 2013 07:22:14 GMT"),
|
|
|
|
MAKE_NV("vary", "Accept-Encoding"),
|
|
|
|
MAKE_NV("via", "1.1 alphabravo (squid/3.x.x), 1.1 nghttpx"),
|
|
|
|
MAKE_NV("x-cache", "HIT from alphabravo"),
|
|
|
|
MAKE_NV("x-cache-lookup", "HIT from alphabravo:3128"),
|
2013-07-27 11:59:30 +02:00
|
|
|
};
|
|
|
|
nghttp2_nv nv5[] = {
|
2015-11-12 16:53:29 +01:00
|
|
|
MAKE_NV(":status", "304 Not Modified"), MAKE_NV("age", "0"),
|
2014-11-27 15:39:04 +01:00
|
|
|
MAKE_NV("cache-control", "max-age=4461139"),
|
|
|
|
MAKE_NV("content-type", "application/x-javascript"),
|
|
|
|
MAKE_NV("date", "Sat, 27 Jul 2013 06:22:12 GMT"),
|
|
|
|
MAKE_NV("expires", "Mon, 16 Sep 2013 21:34:31 GMT"),
|
|
|
|
MAKE_NV("last-modified", "Thu, 05 May 2011 09:15:59 GMT"),
|
|
|
|
MAKE_NV("vary", "Accept-Encoding"),
|
|
|
|
MAKE_NV("via", "1.1 alphabravo (squid/3.x.x), 1.1 nghttpx"),
|
|
|
|
MAKE_NV("x-cache", "HIT from alphabravo"),
|
|
|
|
MAKE_NV("x-cache-lookup", "HIT from alphabravo:3128"),
|
2013-07-27 11:59:30 +02:00
|
|
|
};
|
|
|
|
nghttp2_nv nv6[] = {
|
2015-11-12 16:53:29 +01:00
|
|
|
MAKE_NV(":status", "304 Not Modified"), MAKE_NV("age", "0"),
|
2014-11-27 15:39:04 +01:00
|
|
|
MAKE_NV("cache-control", "max-age=18645951"),
|
|
|
|
MAKE_NV("content-type", "application/x-javascript"),
|
|
|
|
MAKE_NV("date", "Sat, 27 Jul 2013 06:22:12 GMT"),
|
|
|
|
MAKE_NV("expires", "Fri, 28 Feb 2014 01:48:03 GMT"),
|
|
|
|
MAKE_NV("last-modified", "Tue, 12 Jul 2011 16:02:59 GMT"),
|
|
|
|
MAKE_NV("vary", "Accept-Encoding"),
|
|
|
|
MAKE_NV("via", "1.1 alphabravo (squid/3.x.x), 1.1 nghttpx"),
|
|
|
|
MAKE_NV("x-cache", "HIT from alphabravo"),
|
|
|
|
MAKE_NV("x-cache-lookup", "HIT from alphabravo:3128"),
|
2013-07-27 11:59:30 +02:00
|
|
|
};
|
|
|
|
nghttp2_nv nv7[] = {
|
2015-11-12 16:53:29 +01:00
|
|
|
MAKE_NV(":status", "304 Not Modified"), MAKE_NV("age", "0"),
|
2014-11-27 15:39:04 +01:00
|
|
|
MAKE_NV("cache-control", "max-age=31536000"),
|
|
|
|
MAKE_NV("content-type", "application/javascript"),
|
|
|
|
MAKE_NV("date", "Sat, 27 Jul 2013 06:22:12 GMT"),
|
|
|
|
MAKE_NV("etag", "\"6807-4dc5b54e0dcc0\""),
|
|
|
|
MAKE_NV("expires", "Wed, 21 May 2014 08:32:17 GMT"),
|
|
|
|
MAKE_NV("last-modified", "Fri, 10 May 2013 11:18:51 GMT"),
|
|
|
|
MAKE_NV("via", "1.1 alphabravo (squid/3.x.x), 1.1 nghttpx"),
|
|
|
|
MAKE_NV("x-cache", "HIT from alphabravo"),
|
|
|
|
MAKE_NV("x-cache-lookup", "HIT from alphabravo:3128"),
|
2013-07-27 11:59:30 +02:00
|
|
|
};
|
|
|
|
nghttp2_nv nv8[] = {
|
2015-11-12 16:53:29 +01:00
|
|
|
MAKE_NV(":status", "304 Not Modified"), MAKE_NV("age", "0"),
|
2014-11-27 15:39:04 +01:00
|
|
|
MAKE_NV("cache-control", "max-age=31536000"),
|
|
|
|
MAKE_NV("content-type", "application/javascript"),
|
|
|
|
MAKE_NV("date", "Sat, 27 Jul 2013 06:22:12 GMT"),
|
|
|
|
MAKE_NV("etag", "\"41c6-4de7d28585b00\""),
|
|
|
|
MAKE_NV("expires", "Thu, 12 Jun 2014 10:00:58 GMT"),
|
|
|
|
MAKE_NV("last-modified", "Thu, 06 Jun 2013 14:30:36 GMT"),
|
|
|
|
MAKE_NV("via", "1.1 alphabravo (squid/3.x.x), 1.1 nghttpx"),
|
|
|
|
MAKE_NV("x-cache", "HIT from alphabravo"),
|
|
|
|
MAKE_NV("x-cache-lookup", "HIT from alphabravo:3128"),
|
2013-07-27 11:59:30 +02:00
|
|
|
};
|
|
|
|
nghttp2_nv nv9[] = {
|
2015-11-12 16:53:29 +01:00
|
|
|
MAKE_NV(":status", "304 Not Modified"), MAKE_NV("age", "0"),
|
2014-11-27 15:39:04 +01:00
|
|
|
MAKE_NV("cache-control", "max-age=31536000"),
|
|
|
|
MAKE_NV("content-type", "application/javascript"),
|
|
|
|
MAKE_NV("date", "Sat, 27 Jul 2013 06:22:12 GMT"),
|
|
|
|
MAKE_NV("etag", "\"19d6e-4dc5b35a541c0\""),
|
|
|
|
MAKE_NV("expires", "Wed, 21 May 2014 08:32:18 GMT"),
|
|
|
|
MAKE_NV("last-modified", "Fri, 10 May 2013 11:10:07 GMT"),
|
|
|
|
MAKE_NV("via", "1.1 alphabravo (squid/3.x.x), 1.1 nghttpx"),
|
|
|
|
MAKE_NV("x-cache", "HIT from alphabravo"),
|
|
|
|
MAKE_NV("x-cache-lookup", "HIT from alphabravo:3128"),
|
2013-07-27 11:59:30 +02:00
|
|
|
};
|
|
|
|
nghttp2_nv nv10[] = {
|
2015-11-12 16:53:29 +01:00
|
|
|
MAKE_NV(":status", "304 Not Modified"), MAKE_NV("age", "0"),
|
2014-11-27 15:39:04 +01:00
|
|
|
MAKE_NV("cache-control", "max-age=56682045"),
|
|
|
|
MAKE_NV("content-type", "text/css"),
|
|
|
|
MAKE_NV("date", "Sat, 27 Jul 2013 06:22:12 GMT"),
|
|
|
|
MAKE_NV("expires", "Thu, 14 May 2015 07:22:57 GMT"),
|
|
|
|
MAKE_NV("last-modified", "Tue, 14 May 2013 07:21:53 GMT"),
|
|
|
|
MAKE_NV("vary", "Accept-Encoding"),
|
|
|
|
MAKE_NV("via", "1.1 alphabravo (squid/3.x.x), 1.1 nghttpx"),
|
|
|
|
MAKE_NV("x-cache", "HIT from alphabravo"),
|
|
|
|
MAKE_NV("x-cache-lookup", "HIT from alphabravo:3128"),
|
2013-07-27 11:59:30 +02:00
|
|
|
};
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem *mem;
|
2013-07-27 11:59:30 +02:00
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
mem = nghttp2_mem_default();
|
|
|
|
|
|
|
|
nghttp2_hd_deflate_init(&deflater, mem);
|
|
|
|
nghttp2_hd_inflate_init(&inflater, mem);
|
2013-07-27 11:59:30 +02:00
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
check_deflate_inflate(&deflater, &inflater, nv1, ARRLEN(nv1), mem);
|
|
|
|
check_deflate_inflate(&deflater, &inflater, nv2, ARRLEN(nv2), mem);
|
|
|
|
check_deflate_inflate(&deflater, &inflater, nv3, ARRLEN(nv3), mem);
|
|
|
|
check_deflate_inflate(&deflater, &inflater, nv4, ARRLEN(nv4), mem);
|
|
|
|
check_deflate_inflate(&deflater, &inflater, nv5, ARRLEN(nv5), mem);
|
|
|
|
check_deflate_inflate(&deflater, &inflater, nv6, ARRLEN(nv6), mem);
|
|
|
|
check_deflate_inflate(&deflater, &inflater, nv7, ARRLEN(nv7), mem);
|
|
|
|
check_deflate_inflate(&deflater, &inflater, nv8, ARRLEN(nv8), mem);
|
|
|
|
check_deflate_inflate(&deflater, &inflater, nv9, ARRLEN(nv9), mem);
|
|
|
|
check_deflate_inflate(&deflater, &inflater, nv10, ARRLEN(nv10), mem);
|
2013-07-28 12:08:49 +02:00
|
|
|
|
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
|
|
|
nghttp2_hd_deflate_free(&deflater);
|
2013-07-27 11:59:30 +02:00
|
|
|
}
|
2014-04-01 18:25:44 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void test_nghttp2_hd_no_index(void) {
|
2014-04-01 18:25:44 +02:00
|
|
|
nghttp2_hd_deflater deflater;
|
|
|
|
nghttp2_hd_inflater inflater;
|
|
|
|
nghttp2_bufs bufs;
|
|
|
|
ssize_t blocklen;
|
|
|
|
nghttp2_nv nva[] = {
|
2014-11-27 15:39:04 +01:00
|
|
|
MAKE_NV(":method", "GET"), MAKE_NV(":method", "POST"),
|
|
|
|
MAKE_NV(":path", "/foo"), MAKE_NV("version", "HTTP/1.1"),
|
|
|
|
MAKE_NV(":method", "GET"),
|
2014-04-01 18:25:44 +02:00
|
|
|
};
|
|
|
|
size_t i;
|
|
|
|
nva_out out;
|
|
|
|
int rv;
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem *mem;
|
|
|
|
|
|
|
|
mem = nghttp2_mem_default();
|
2014-04-01 18:25:44 +02:00
|
|
|
|
|
|
|
/* 1st :method: GET can be indexable, last one is not */
|
2014-11-27 15:39:04 +01:00
|
|
|
for (i = 1; i < ARRLEN(nva); ++i) {
|
2014-04-01 18:25:44 +02:00
|
|
|
nva[i].flags = NGHTTP2_NV_FLAG_NO_INDEX;
|
|
|
|
}
|
|
|
|
|
|
|
|
frame_pack_bufs_init(&bufs);
|
|
|
|
|
|
|
|
nva_out_init(&out);
|
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_hd_deflate_init(&deflater, mem);
|
|
|
|
nghttp2_hd_inflate_init(&inflater, mem);
|
2014-04-01 18:25:44 +02:00
|
|
|
|
2014-05-13 16:42:55 +02:00
|
|
|
rv = nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, ARRLEN(nva));
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = (ssize_t)nghttp2_bufs_len(&bufs);
|
2014-04-01 18:25:44 +02:00
|
|
|
|
|
|
|
CU_ASSERT(0 == rv);
|
|
|
|
CU_ASSERT(blocklen > 0);
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(&inflater, &out, &bufs, 0, mem));
|
2014-04-01 18:25:44 +02:00
|
|
|
|
|
|
|
CU_ASSERT(ARRLEN(nva) == out.nvlen);
|
2015-03-03 15:23:43 +01:00
|
|
|
assert_nv_equal(nva, out.nva, ARRLEN(nva), mem);
|
2014-04-01 18:25:44 +02:00
|
|
|
|
|
|
|
CU_ASSERT(out.nva[0].flags == NGHTTP2_NV_FLAG_NONE);
|
2014-11-27 15:39:04 +01:00
|
|
|
for (i = 1; i < ARRLEN(nva); ++i) {
|
2014-04-01 18:25:44 +02:00
|
|
|
CU_ASSERT(out.nva[i].flags == NGHTTP2_NV_FLAG_NO_INDEX);
|
|
|
|
}
|
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
nva_out_reset(&out, mem);
|
2014-04-01 18:25:44 +02:00
|
|
|
|
|
|
|
nghttp2_bufs_free(&bufs);
|
|
|
|
nghttp2_hd_inflate_free(&inflater);
|
|
|
|
nghttp2_hd_deflate_free(&deflater);
|
|
|
|
}
|
2014-05-13 16:42:55 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void test_nghttp2_hd_deflate_bound(void) {
|
2014-05-13 16:42:55 +02:00
|
|
|
nghttp2_hd_deflater deflater;
|
2014-11-27 15:39:04 +01:00
|
|
|
nghttp2_nv nva[] = {MAKE_NV(":method", "GET"), MAKE_NV("alpha", "bravo")};
|
2014-05-13 16:42:55 +02:00
|
|
|
nghttp2_bufs bufs;
|
|
|
|
size_t bound, bound2;
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem *mem;
|
2014-05-13 16:42:55 +02:00
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
mem = nghttp2_mem_default();
|
2014-05-13 16:42:55 +02:00
|
|
|
frame_pack_bufs_init(&bufs);
|
|
|
|
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_hd_deflate_init(&deflater, mem);
|
2014-05-13 16:42:55 +02:00
|
|
|
|
|
|
|
bound = nghttp2_hd_deflate_bound(&deflater, nva, ARRLEN(nva));
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
CU_ASSERT(12 + 6 * 2 * 2 + nva[0].namelen + nva[0].valuelen + nva[1].namelen +
|
|
|
|
nva[1].valuelen ==
|
|
|
|
bound);
|
2014-05-13 16:42:55 +02:00
|
|
|
|
|
|
|
nghttp2_hd_deflate_hd_bufs(&deflater, &bufs, nva, ARRLEN(nva));
|
|
|
|
|
|
|
|
CU_ASSERT(bound > (size_t)nghttp2_bufs_len(&bufs));
|
|
|
|
|
|
|
|
bound2 = nghttp2_hd_deflate_bound(&deflater, nva, ARRLEN(nva));
|
|
|
|
|
2014-07-12 11:47:55 +02:00
|
|
|
CU_ASSERT(bound == bound2);
|
2014-05-13 16:42:55 +02:00
|
|
|
|
|
|
|
nghttp2_bufs_free(&bufs);
|
|
|
|
nghttp2_hd_deflate_free(&deflater);
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void test_nghttp2_hd_public_api(void) {
|
2014-05-13 16:42:55 +02:00
|
|
|
nghttp2_hd_deflater *deflater;
|
|
|
|
nghttp2_hd_inflater *inflater;
|
2014-11-27 15:39:04 +01:00
|
|
|
nghttp2_nv nva[] = {MAKE_NV("alpha", "bravo"), MAKE_NV("charlie", "delta")};
|
2014-05-13 16:42:55 +02:00
|
|
|
uint8_t buf[4096];
|
|
|
|
size_t buflen;
|
|
|
|
ssize_t blocklen;
|
|
|
|
nghttp2_bufs bufs;
|
2014-12-07 15:07:13 +01:00
|
|
|
nghttp2_mem *mem;
|
|
|
|
|
|
|
|
mem = nghttp2_mem_default();
|
2014-05-13 16:42:55 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2015-09-23 07:41:53 +02:00
|
|
|
nghttp2_bufs_wrap_init(&bufs, buf, (size_t)blocklen, mem);
|
2014-05-13 16:42:55 +02:00
|
|
|
bufs.head->buf.last += blocklen;
|
|
|
|
|
2015-03-03 15:23:43 +01:00
|
|
|
CU_ASSERT(blocklen == inflate_hd(inflater, NULL, &bufs, 0, mem));
|
2014-05-13 16:42:55 +02:00
|
|
|
|
|
|
|
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));
|
|
|
|
|
2015-09-23 07:41:53 +02:00
|
|
|
blocklen = nghttp2_hd_deflate_hd(deflater, buf, (size_t)(blocklen - 1), nva,
|
|
|
|
ARRLEN(nva));
|
2014-05-13 16:42:55 +02:00
|
|
|
|
|
|
|
CU_ASSERT(NGHTTP2_ERR_INSUFF_BUFSIZE == blocklen);
|
|
|
|
|
|
|
|
nghttp2_hd_deflate_del(deflater);
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
static size_t encode_length(uint8_t *buf, uint64_t n, size_t prefix) {
|
2015-09-23 11:07:38 +02:00
|
|
|
size_t k = (size_t)((1 << prefix) - 1);
|
2014-07-22 15:38:18 +02:00
|
|
|
size_t len = 0;
|
2015-09-23 11:07:38 +02:00
|
|
|
*buf = (uint8_t)(*buf & ~k);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (n >= k) {
|
2015-09-23 11:07:38 +02:00
|
|
|
*buf = (uint8_t)(*buf | k);
|
|
|
|
++buf;
|
2014-07-22 15:38:18 +02:00
|
|
|
n -= k;
|
|
|
|
++len;
|
|
|
|
} else {
|
2015-09-23 11:07:38 +02:00
|
|
|
*buf = (uint8_t)(*buf | n);
|
|
|
|
++buf;
|
2014-07-22 15:38:18 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
++len;
|
2014-11-27 15:39:04 +01:00
|
|
|
if (n >= 128) {
|
2015-09-23 11:07:38 +02:00
|
|
|
*buf = (uint8_t)((1 << 7) | (n & 0x7f));
|
|
|
|
++buf;
|
2014-07-22 15:38:18 +02:00
|
|
|
n >>= 7;
|
|
|
|
} else {
|
|
|
|
*buf++ = (uint8_t)n;
|
|
|
|
break;
|
|
|
|
}
|
2014-11-27 15:39:04 +01:00
|
|
|
} while (n);
|
2014-07-22 15:38:18 +02:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void test_nghttp2_hd_decode_length(void) {
|
2014-07-22 15:38:18 +02:00
|
|
|
uint32_t out;
|
|
|
|
size_t shift;
|
|
|
|
int final;
|
|
|
|
uint8_t buf[16];
|
|
|
|
uint8_t *bufp;
|
|
|
|
size_t len;
|
|
|
|
ssize_t rv;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
len = encode_length(buf, UINT32_MAX, 7);
|
|
|
|
|
|
|
|
rv = nghttp2_hd_decode_length(&out, &shift, &final, 0, 0, buf, buf + len, 7);
|
|
|
|
|
|
|
|
CU_ASSERT((ssize_t)len == rv);
|
|
|
|
CU_ASSERT(0 != final);
|
|
|
|
CU_ASSERT(UINT32_MAX == out);
|
|
|
|
|
|
|
|
/* Make sure that we can decode integer if we feed 1 byte at a
|
|
|
|
time */
|
|
|
|
out = 0;
|
|
|
|
shift = 0;
|
|
|
|
final = 0;
|
|
|
|
bufp = buf;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
for (i = 0; i < len; ++i, ++bufp) {
|
|
|
|
rv = nghttp2_hd_decode_length(&out, &shift, &final, out, shift, bufp,
|
|
|
|
bufp + 1, 7);
|
2014-07-22 15:38:18 +02:00
|
|
|
|
|
|
|
CU_ASSERT(rv == 1);
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (final) {
|
2014-07-22 15:38:18 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CU_ASSERT(i == len - 1);
|
|
|
|
CU_ASSERT(0 != final);
|
|
|
|
CU_ASSERT(UINT32_MAX == out);
|
|
|
|
|
|
|
|
/* Check overflow case */
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
len = encode_length(buf, 1ll << 32, 7);
|
|
|
|
|
|
|
|
rv = nghttp2_hd_decode_length(&out, &shift, &final, 0, 0, buf, buf + len, 7);
|
|
|
|
|
|
|
|
CU_ASSERT(-1 == rv);
|
|
|
|
}
|
2014-12-18 17:28:21 +01:00
|
|
|
|
|
|
|
void test_nghttp2_hd_huff_encode(void) {
|
|
|
|
int rv;
|
|
|
|
ssize_t len;
|
|
|
|
nghttp2_bufs bufs, outbufs;
|
|
|
|
nghttp2_hd_huff_decode_context ctx;
|
|
|
|
const uint8_t t1[] = {22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11,
|
|
|
|
10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
|
|
|
|
|
|
|
|
frame_pack_bufs_init(&bufs);
|
|
|
|
frame_pack_bufs_init(&outbufs);
|
|
|
|
|
|
|
|
rv = nghttp2_hd_huff_encode(&bufs, t1, sizeof(t1));
|
|
|
|
|
|
|
|
CU_ASSERT(rv == 0);
|
|
|
|
|
|
|
|
nghttp2_hd_huff_decode_context_init(&ctx);
|
|
|
|
|
|
|
|
len = nghttp2_hd_huff_decode(&ctx, &outbufs, bufs.cur->buf.pos,
|
|
|
|
nghttp2_bufs_len(&bufs), 1);
|
|
|
|
|
2015-09-23 07:41:53 +02:00
|
|
|
CU_ASSERT((ssize_t)nghttp2_bufs_len(&bufs) == len);
|
2014-12-18 17:28:21 +01:00
|
|
|
CU_ASSERT((ssize_t)sizeof(t1) == nghttp2_bufs_len(&outbufs));
|
|
|
|
|
|
|
|
CU_ASSERT(0 == memcmp(t1, outbufs.cur->buf.pos, sizeof(t1)));
|
|
|
|
|
|
|
|
nghttp2_bufs_free(&bufs);
|
|
|
|
nghttp2_bufs_free(&outbufs);
|
|
|
|
}
|