2013-11-10 12:46:18 +01:00
|
|
|
/*
|
|
|
|
* nghttp2 - HTTP/2.0 C Library
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2014-01-08 15:30:02 +01:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif /* HAVE_CONFIG_H */
|
|
|
|
|
2013-10-21 17:42:46 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <assert.h>
|
2013-10-26 16:31:41 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
2013-10-21 17:42:46 +02:00
|
|
|
|
|
|
|
#include <jansson.h>
|
|
|
|
|
|
|
|
#include "nghttp2_hd.h"
|
2013-10-26 15:46:44 +02:00
|
|
|
#include "nghttp2_frame.h"
|
2013-10-21 17:42:46 +02:00
|
|
|
|
2013-10-26 18:04:42 +02:00
|
|
|
#include "comp_helper.h"
|
|
|
|
|
2013-10-26 16:31:41 +02:00
|
|
|
typedef struct {
|
|
|
|
size_t table_size;
|
2013-10-28 16:42:08 +01:00
|
|
|
size_t deflate_table_size;
|
2013-12-06 15:17:38 +01:00
|
|
|
nghttp2_hd_side side;
|
2013-10-26 16:31:41 +02:00
|
|
|
int http1text;
|
2013-10-26 18:04:42 +02:00
|
|
|
int dump_header_table;
|
2013-12-05 15:22:10 +01:00
|
|
|
int no_refset;
|
2013-10-26 16:31:41 +02:00
|
|
|
} deflate_config;
|
|
|
|
|
|
|
|
static deflate_config config;
|
|
|
|
|
2013-11-17 16:15:08 +01:00
|
|
|
static size_t input_sum;
|
|
|
|
static size_t output_sum;
|
|
|
|
|
2014-01-11 07:31:36 +01:00
|
|
|
static char to_hex_digit(uint8_t n)
|
|
|
|
{
|
|
|
|
if(n > 9) {
|
|
|
|
return n - 10 + 'a';
|
|
|
|
}
|
|
|
|
return n + '0';
|
|
|
|
}
|
|
|
|
|
2013-10-21 17:42:46 +02:00
|
|
|
static void to_hex(char *dest, const uint8_t *src, size_t len)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
for(i = 0; i < len; ++i) {
|
2014-01-11 07:31:36 +01:00
|
|
|
*dest++ = to_hex_digit(src[i] >> 4);
|
|
|
|
*dest++ = to_hex_digit(src[i] & 0xf);
|
2013-10-21 17:42:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-26 18:04:42 +02:00
|
|
|
static void output_to_json(nghttp2_hd_context *deflater,
|
|
|
|
const uint8_t *buf, size_t len, size_t inputlen,
|
2014-01-11 07:31:36 +01:00
|
|
|
nghttp2_nv *nva, size_t nvlen,
|
2013-10-21 17:42:46 +02:00
|
|
|
int seq)
|
|
|
|
{
|
|
|
|
json_t *obj;
|
2014-01-11 07:31:36 +01:00
|
|
|
char *hex = NULL;
|
2013-10-21 17:42:46 +02:00
|
|
|
|
2014-01-11 07:31:36 +01:00
|
|
|
if(len > 0) {
|
|
|
|
hex = malloc(len * 2);
|
2013-10-21 17:42:46 +02:00
|
|
|
}
|
|
|
|
obj = json_object();
|
|
|
|
json_object_set_new(obj, "seq", json_integer(seq));
|
2014-01-11 07:31:36 +01:00
|
|
|
json_object_set_new(obj, "input_length", json_integer(inputlen));
|
|
|
|
json_object_set_new(obj, "output_length", json_integer(len));
|
|
|
|
json_object_set_new(obj, "percentage_of_original_size",
|
2013-10-21 17:42:46 +02:00
|
|
|
json_real((double)len / inputlen * 100));
|
|
|
|
to_hex(hex, buf, len);
|
2014-01-24 13:54:00 +01:00
|
|
|
if(len == 0) {
|
|
|
|
json_object_set_new(obj, "wire", json_string(""));
|
|
|
|
} else {
|
|
|
|
json_object_set_new(obj, "wire", json_pack("s#", hex, len * 2));
|
|
|
|
}
|
2014-01-11 07:31:36 +01:00
|
|
|
json_object_set_new(obj, "headers", dump_headers(nva, nvlen));
|
|
|
|
json_object_set_new(obj, "header_table_size",
|
|
|
|
json_integer(config.table_size));
|
2013-10-26 18:04:42 +02:00
|
|
|
if(config.dump_header_table) {
|
2014-01-11 07:31:36 +01:00
|
|
|
json_object_set_new(obj, "header_table", dump_header_table(deflater));
|
2013-10-26 18:04:42 +02:00
|
|
|
}
|
|
|
|
json_dumpf(obj, stdout, JSON_PRESERVE_ORDER | JSON_INDENT(2));
|
2013-10-21 17:42:46 +02:00
|
|
|
printf("\n");
|
|
|
|
json_decref(obj);
|
2014-01-11 07:31:36 +01:00
|
|
|
free(hex);
|
2013-10-21 17:42:46 +02:00
|
|
|
}
|
|
|
|
|
2013-10-26 15:46:44 +02:00
|
|
|
static void deflate_hd(nghttp2_hd_context *deflater,
|
|
|
|
nghttp2_nv *nva, size_t nvlen, size_t inputlen, int seq)
|
2013-10-21 17:42:46 +02:00
|
|
|
{
|
2013-10-26 15:46:44 +02:00
|
|
|
ssize_t rv;
|
2013-10-21 17:42:46 +02:00
|
|
|
uint8_t *buf = NULL;
|
|
|
|
size_t buflen = 0;
|
2013-10-26 15:46:44 +02:00
|
|
|
rv = nghttp2_hd_deflate_hd(deflater, &buf, &buflen, 0, nva, nvlen);
|
|
|
|
if(rv < 0) {
|
|
|
|
fprintf(stderr, "deflate failed with error code %zd at %d\n", rv, seq);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2013-11-17 16:15:08 +01:00
|
|
|
input_sum += inputlen;
|
|
|
|
output_sum += rv;
|
2014-01-11 07:31:36 +01:00
|
|
|
output_to_json(deflater, buf, rv, inputlen, nva, nvlen, seq);
|
2013-10-26 15:46:44 +02:00
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int deflate_hd_json(json_t *obj, nghttp2_hd_context *deflater, int seq)
|
|
|
|
{
|
|
|
|
json_t *js;
|
2013-10-21 17:42:46 +02:00
|
|
|
nghttp2_nv nva[128];
|
|
|
|
size_t len;
|
|
|
|
size_t i;
|
|
|
|
size_t inputlen = 0;
|
|
|
|
|
|
|
|
js = json_object_get(obj, "headers");
|
|
|
|
if(js == NULL) {
|
2014-01-11 07:31:36 +01:00
|
|
|
fprintf(stderr, "'headers' key is missing at %d\n", seq);
|
2013-10-21 17:42:46 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if(!json_is_array(js)) {
|
2014-01-11 07:31:36 +01:00
|
|
|
fprintf(stderr,
|
|
|
|
"The value of 'headers' key must be an array at %d\n", seq);
|
2013-10-21 17:42:46 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
len = json_array_size(js);
|
|
|
|
if(len > sizeof(nva)/sizeof(nva[0])) {
|
|
|
|
fprintf(stderr, "Too many headers (> %zu) at %d\n",
|
|
|
|
sizeof(nva)/sizeof(nva[0]), seq);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
for(i = 0; i < len; ++i) {
|
|
|
|
json_t *nv_pair = json_array_get(js, i);
|
2014-01-11 07:31:36 +01:00
|
|
|
const char *name;
|
|
|
|
json_t *value;
|
|
|
|
if(!json_is_object(nv_pair) || json_object_size(nv_pair) != 1) {
|
|
|
|
fprintf(stderr, "bad formatted name/value pair object at %d\n", seq);
|
2013-10-21 17:42:46 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2014-01-11 07:31:36 +01:00
|
|
|
json_object_foreach(nv_pair, name, value) {
|
|
|
|
nva[i].name = (uint8_t*)name;
|
|
|
|
nva[i].namelen = strlen(name);
|
2013-10-21 17:42:46 +02:00
|
|
|
|
2014-01-11 07:31:36 +01:00
|
|
|
if(!json_is_string(value)) {
|
|
|
|
fprintf(stderr, "value is not string at %d\n", seq);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
nva[i].value = (uint8_t*)json_string_value(value);
|
|
|
|
nva[i].valuelen = strlen(json_string_value(value));
|
2013-10-21 17:42:46 +02:00
|
|
|
}
|
|
|
|
inputlen += nva[i].namelen + nva[i].valuelen;
|
|
|
|
}
|
2013-10-26 15:46:44 +02:00
|
|
|
deflate_hd(deflater, nva, len, inputlen, seq);
|
2013-10-21 17:42:46 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-01-11 07:31:36 +01:00
|
|
|
static void init_deflater(nghttp2_hd_context *deflater, nghttp2_hd_side side)
|
|
|
|
{
|
|
|
|
nghttp2_hd_deflate_init2(deflater, side, config.deflate_table_size);
|
|
|
|
nghttp2_hd_deflate_set_no_refset(deflater, config.no_refset);
|
|
|
|
nghttp2_hd_change_table_size(deflater, config.table_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void deinit_deflater(nghttp2_hd_context *deflater)
|
|
|
|
{
|
|
|
|
nghttp2_hd_deflate_free(deflater);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int perform(void)
|
2013-10-21 17:42:46 +02:00
|
|
|
{
|
2013-10-21 17:50:09 +02:00
|
|
|
size_t i;
|
2014-01-11 07:31:36 +01:00
|
|
|
json_t *json, *cases;
|
2013-10-21 17:42:46 +02:00
|
|
|
json_error_t error;
|
|
|
|
size_t len;
|
2014-01-11 07:31:36 +01:00
|
|
|
nghttp2_hd_context deflater;
|
|
|
|
nghttp2_hd_side side;
|
|
|
|
|
2013-10-21 17:42:46 +02:00
|
|
|
json = json_loadf(stdin, 0, &error);
|
|
|
|
if(json == NULL) {
|
|
|
|
fprintf(stderr, "JSON loading failed\n");
|
2013-10-21 17:50:09 +02:00
|
|
|
exit(EXIT_FAILURE);
|
2013-10-21 17:42:46 +02:00
|
|
|
}
|
2014-01-11 07:31:36 +01:00
|
|
|
if(strcmp("request", json_string_value(json_object_get(json, "context")))
|
|
|
|
== 0) {
|
|
|
|
side = NGHTTP2_HD_SIDE_REQUEST;
|
|
|
|
} else {
|
|
|
|
side = NGHTTP2_HD_SIDE_RESPONSE;
|
|
|
|
}
|
|
|
|
cases = json_object_get(json, "cases");
|
|
|
|
if(cases == NULL) {
|
|
|
|
fprintf(stderr, "Missing 'cases' key in root object\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
if(!json_is_array(cases)) {
|
|
|
|
fprintf(stderr, "'cases' must be JSON array\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
init_deflater(&deflater, side);
|
|
|
|
output_json_header(side);
|
|
|
|
len = json_array_size(cases);
|
2013-10-21 17:42:46 +02:00
|
|
|
for(i = 0; i < len; ++i) {
|
2014-01-11 07:31:36 +01:00
|
|
|
json_t *obj = json_array_get(cases, i);
|
2013-10-21 17:42:46 +02:00
|
|
|
if(!json_is_object(obj)) {
|
2013-10-21 17:50:09 +02:00
|
|
|
fprintf(stderr, "Unexpected JSON type at %zu. It should be object.\n",
|
|
|
|
i);
|
2013-10-21 17:42:46 +02:00
|
|
|
continue;
|
|
|
|
}
|
2014-01-11 07:31:36 +01:00
|
|
|
if(deflate_hd_json(obj, &deflater, i) != 0) {
|
2013-10-21 17:42:46 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(i + 1 < len) {
|
|
|
|
printf(",\n");
|
|
|
|
}
|
|
|
|
}
|
2014-01-11 07:31:36 +01:00
|
|
|
output_json_footer();
|
|
|
|
deinit_deflater(&deflater);
|
2013-10-21 17:42:46 +02:00
|
|
|
json_decref(json);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-01-11 07:31:36 +01:00
|
|
|
static int perform_from_http1text(void)
|
2013-10-26 15:46:44 +02:00
|
|
|
{
|
|
|
|
char line[1 << 14];
|
|
|
|
nghttp2_nv nva[256];
|
|
|
|
int seq = 0;
|
2014-01-11 07:31:36 +01:00
|
|
|
nghttp2_hd_context deflater;
|
|
|
|
init_deflater(&deflater, config.side);
|
|
|
|
output_json_header(config.side);
|
2013-10-26 15:46:44 +02:00
|
|
|
for(;;) {
|
|
|
|
size_t nvlen = 0;
|
|
|
|
int end = 0;
|
|
|
|
size_t inputlen = 0;
|
|
|
|
size_t i;
|
|
|
|
for(;;) {
|
|
|
|
nghttp2_nv *nv;
|
|
|
|
char *rv = fgets(line, sizeof(line), stdin);
|
|
|
|
char *val, *val_end;
|
|
|
|
if(rv == NULL) {
|
|
|
|
end = 1;
|
|
|
|
break;
|
|
|
|
} else if(line[0] == '\n') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
assert(nvlen < sizeof(nva)/sizeof(nva[0]));
|
|
|
|
nv = &nva[nvlen];
|
|
|
|
val = strchr(line+1, ':');
|
|
|
|
if(val == NULL) {
|
|
|
|
fprintf(stderr, "Bad HTTP/1 header field format at %d.\n", seq);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
*val = '\0';
|
|
|
|
++val;
|
|
|
|
for(; *val && (*val == ' ' || *val == '\t'); ++val);
|
|
|
|
for(val_end = val; *val_end && (*val_end != '\r' && *val_end != '\n');
|
|
|
|
++val_end);
|
|
|
|
*val_end = '\0';
|
|
|
|
/* printf("[%s] : [%s]\n", line, val); */
|
|
|
|
nv->namelen = strlen(line);
|
|
|
|
nv->valuelen = strlen(val);
|
|
|
|
nv->name = (uint8_t*)strdup(line);
|
|
|
|
nv->value = (uint8_t*)strdup(val);
|
|
|
|
++nvlen;
|
|
|
|
inputlen += nv->namelen + nv->valuelen;
|
|
|
|
}
|
|
|
|
|
2013-11-17 14:49:38 +01:00
|
|
|
if(!end) {
|
|
|
|
if(seq > 0) {
|
|
|
|
printf(",\n");
|
|
|
|
}
|
2014-01-11 07:31:36 +01:00
|
|
|
deflate_hd(&deflater, nva, nvlen, inputlen, seq);
|
2013-11-17 14:49:38 +01:00
|
|
|
}
|
2013-10-26 15:46:44 +02:00
|
|
|
|
|
|
|
for(i = 0; i < nvlen; ++i) {
|
|
|
|
free(nva[i].name);
|
|
|
|
free(nva[i].value);
|
|
|
|
}
|
|
|
|
if(end) break;
|
|
|
|
++seq;
|
|
|
|
}
|
2014-01-11 07:31:36 +01:00
|
|
|
output_json_footer();
|
|
|
|
deinit_deflater(&deflater);
|
2013-10-26 15:46:44 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-21 17:50:09 +02:00
|
|
|
static void print_help(void)
|
2013-10-21 17:42:46 +02:00
|
|
|
{
|
2014-01-08 13:44:44 +01:00
|
|
|
printf("HPACK HTTP/2.0 header encoder\n"
|
2013-10-26 16:31:41 +02:00
|
|
|
"Usage: deflatehd [OPTIONS] < INPUT\n"
|
2013-10-26 15:46:44 +02:00
|
|
|
"\n"
|
2014-01-11 07:31:36 +01:00
|
|
|
"Reads JSON data or HTTP/1-style header fields from stdin and\n"
|
2013-10-26 15:46:44 +02:00
|
|
|
"outputs deflated header block in JSON array.\n"
|
|
|
|
"\n"
|
2014-01-11 07:31:36 +01:00
|
|
|
"For the JSON input, the root JSON object must contain \"context\"\n"
|
|
|
|
"key, which indicates which compression context is used. If it is\n"
|
|
|
|
"\"request\", request compression context is used. Otherwise,\n"
|
|
|
|
"response compression context is used. The value of \"cases\" key\n"
|
|
|
|
"contains the sequence of input header set. They share the same\n"
|
|
|
|
"compression context and are processed in the order they appear.\n"
|
|
|
|
"Each item in the sequence is a JSON object and it must have at\n"
|
|
|
|
"least \"headers\" key. Its value is an array of a JSON object\n"
|
|
|
|
"containing exactly one name/value pair.\n"
|
2013-10-21 17:42:46 +02:00
|
|
|
"\n"
|
|
|
|
"Example:\n"
|
2014-01-11 07:31:36 +01:00
|
|
|
"{\n"
|
|
|
|
" \"context\": \"request\",\n"
|
|
|
|
" \"cases\":\n"
|
|
|
|
" [\n"
|
|
|
|
" {\n"
|
|
|
|
" \"headers\": [\n"
|
|
|
|
" { \":method\": \"GET\" },\n"
|
|
|
|
" { \":path\": \"/\" }\n"
|
|
|
|
" ]\n"
|
|
|
|
" },\n"
|
|
|
|
" {\n"
|
|
|
|
" \"headers\": [\n"
|
|
|
|
" { \":method\": \"POST\" },\n"
|
|
|
|
" { \":path\": \"/\" }\n"
|
|
|
|
" ]\n"
|
|
|
|
" }\n"
|
|
|
|
" ]\n"
|
|
|
|
"}\n"
|
2013-10-21 17:42:46 +02:00
|
|
|
"\n"
|
2013-10-26 15:46:44 +02:00
|
|
|
"With -t option, the program can accept more familiar HTTP/1 style\n"
|
2013-11-17 14:49:38 +01:00
|
|
|
"header field block. Each header set must be followed by one empty\n"
|
|
|
|
"line:\n"
|
2013-10-26 15:46:44 +02:00
|
|
|
"\n"
|
|
|
|
"Example:\n"
|
|
|
|
":method: GET\n"
|
|
|
|
":scheme: https\n"
|
|
|
|
":path: /\n"
|
|
|
|
"\n"
|
|
|
|
":method: POST\n"
|
|
|
|
"user-agent: nghttp2\n"
|
|
|
|
"\n"
|
2013-10-21 17:42:46 +02:00
|
|
|
"The output of this program can be used as input for inflatehd.\n"
|
|
|
|
"\n"
|
|
|
|
"OPTIONS:\n"
|
|
|
|
" -r, --response Use response compression context instead of\n"
|
2014-01-11 07:31:36 +01:00
|
|
|
" request if -t is used. For JSON input, it is\n"
|
|
|
|
" determined by inspecting \"context\" key in\n"
|
|
|
|
" root JSON object.\n"
|
2013-10-26 15:46:44 +02:00
|
|
|
" -t, --http1text Use HTTP/1 style header field text as input.\n"
|
|
|
|
" Each header set is delimited by single empty\n"
|
2013-10-26 16:31:41 +02:00
|
|
|
" line.\n"
|
|
|
|
" -s, --table-size=<N>\n"
|
2013-10-26 18:04:42 +02:00
|
|
|
" Set dynamic table size. In the HPACK\n"
|
2013-10-26 16:31:41 +02:00
|
|
|
" specification, this value is denoted by\n"
|
|
|
|
" SETTINGS_HEADER_TABLE_SIZE.\n"
|
|
|
|
" Default: 4096\n"
|
2013-10-28 16:42:08 +01:00
|
|
|
" -S, --deflate-table-size=<N>\n"
|
2013-10-26 18:04:42 +02:00
|
|
|
" Use first N bytes of dynamic header table\n"
|
|
|
|
" buffer.\n"
|
|
|
|
" Default: 4096\n"
|
|
|
|
" -d, --dump-header-table\n"
|
2013-12-05 15:22:10 +01:00
|
|
|
" Output dynamic header table.\n"
|
|
|
|
" -c, --no-refset Don't use reference set.\n");
|
2013-10-21 17:42:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct option long_options[] = {
|
|
|
|
{"response", no_argument, NULL, 'r'},
|
2013-10-26 15:46:44 +02:00
|
|
|
{"http1text", no_argument, NULL, 't'},
|
2013-10-26 16:31:41 +02:00
|
|
|
{"table-size", required_argument, NULL, 's'},
|
2013-10-28 16:42:08 +01:00
|
|
|
{"deflate-table-size", required_argument, NULL, 'S'},
|
2013-10-26 18:04:42 +02:00
|
|
|
{"dump-header-table", no_argument, NULL, 'd'},
|
2013-12-05 15:22:10 +01:00
|
|
|
{"no-refset", no_argument, NULL, 'c'},
|
2013-10-21 17:42:46 +02:00
|
|
|
{NULL, 0, NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2013-10-26 16:31:41 +02:00
|
|
|
char *end;
|
|
|
|
|
|
|
|
config.side = NGHTTP2_HD_SIDE_REQUEST;
|
|
|
|
config.table_size = NGHTTP2_HD_DEFAULT_MAX_BUFFER_SIZE;
|
2013-10-28 16:42:08 +01:00
|
|
|
config.deflate_table_size = NGHTTP2_HD_DEFAULT_MAX_DEFLATE_BUFFER_SIZE;
|
2013-10-26 16:31:41 +02:00
|
|
|
config.http1text = 0;
|
2013-10-26 18:04:42 +02:00
|
|
|
config.dump_header_table = 0;
|
2013-12-05 15:22:10 +01:00
|
|
|
config.no_refset = 0;
|
2013-10-21 17:42:46 +02:00
|
|
|
while(1) {
|
|
|
|
int option_index = 0;
|
2013-12-05 15:22:10 +01:00
|
|
|
int c = getopt_long(argc, argv, "S:cdhrs:t", long_options, &option_index);
|
2013-10-21 17:42:46 +02:00
|
|
|
if(c == -1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch(c) {
|
|
|
|
case 'r':
|
|
|
|
/* --response */
|
2013-10-26 16:31:41 +02:00
|
|
|
config.side = NGHTTP2_HD_SIDE_RESPONSE;
|
2013-10-21 17:42:46 +02:00
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
print_help();
|
|
|
|
exit(EXIT_SUCCESS);
|
2013-10-26 15:46:44 +02:00
|
|
|
case 't':
|
2013-10-26 16:31:41 +02:00
|
|
|
/* --http1text */
|
|
|
|
config.http1text = 1;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
/* --table-size */
|
2014-01-18 07:32:50 +01:00
|
|
|
errno = 0;
|
2013-10-26 16:31:41 +02:00
|
|
|
config.table_size = strtoul(optarg, &end, 10);
|
|
|
|
if(errno == ERANGE || *end != '\0') {
|
|
|
|
fprintf(stderr, "-s: Bad option value\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'S':
|
2013-10-28 16:42:08 +01:00
|
|
|
/* --deflate-table-size */
|
2014-01-18 07:32:50 +01:00
|
|
|
errno = 0;
|
2013-10-28 16:42:08 +01:00
|
|
|
config.deflate_table_size = strtoul(optarg, &end, 10);
|
2013-10-26 16:31:41 +02:00
|
|
|
if(errno == ERANGE || *end != '\0') {
|
|
|
|
fprintf(stderr, "-S: Bad option value\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2013-10-26 15:46:44 +02:00
|
|
|
break;
|
2013-10-26 18:04:42 +02:00
|
|
|
case 'd':
|
|
|
|
/* --dump-header-table */
|
|
|
|
config.dump_header_table = 1;
|
|
|
|
break;
|
2013-12-05 15:22:10 +01:00
|
|
|
case 'c':
|
|
|
|
/* --no-refset */
|
|
|
|
config.no_refset = 1;
|
|
|
|
break;
|
2013-10-21 17:42:46 +02:00
|
|
|
case '?':
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-10-26 16:31:41 +02:00
|
|
|
if(config.http1text) {
|
2014-01-11 07:31:36 +01:00
|
|
|
perform_from_http1text();
|
2013-10-26 15:46:44 +02:00
|
|
|
} else {
|
2014-01-11 07:31:36 +01:00
|
|
|
perform();
|
2013-10-26 15:46:44 +02:00
|
|
|
}
|
2013-11-17 16:15:08 +01:00
|
|
|
fprintf(stderr, "Overall: input=%zu output=%zu ratio=%.02f\n",
|
|
|
|
input_sum, output_sum, (double)output_sum / input_sum);
|
2013-10-21 17:42:46 +02:00
|
|
|
return 0;
|
|
|
|
}
|