Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
495788df
Commit
495788df
authored
Oct 26, 2013
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hdtest: Add option to specify table size
parent
22df6f41
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
105 additions
and
29 deletions
+105
-29
hdtest/deflatehd.c
hdtest/deflatehd.c
+68
-21
hdtest/inflatehd.c
hdtest/inflatehd.c
+37
-8
No files found.
hdtest/deflatehd.c
View file @
495788df
...
...
@@ -3,12 +3,23 @@
#include <unistd.h>
#include <getopt.h>
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <jansson.h>
#include "nghttp2_hd.h"
#include "nghttp2_frame.h"
typedef
struct
{
nghttp2_hd_side
side
;
size_t
table_size
;
size_t
local_table_size
;
int
http1text
;
}
deflate_config
;
static
deflate_config
config
;
static
void
to_hex
(
char
*
dest
,
const
uint8_t
*
src
,
size_t
len
)
{
size_t
i
;
...
...
@@ -108,9 +119,8 @@ static int deflate_hd_json(json_t *obj, nghttp2_hd_context *deflater, int seq)
return
0
;
}
static
int
perform
(
nghttp2_hd_
side
side
)
static
int
perform
(
nghttp2_hd_
context
*
deflater
)
{
nghttp2_hd_context
deflater
;
size_t
i
;
json_t
*
json
;
json_error_t
error
;
...
...
@@ -120,7 +130,6 @@ static int perform(nghttp2_hd_side side)
fprintf
(
stderr
,
"JSON loading failed
\n
"
);
exit
(
EXIT_FAILURE
);
}
nghttp2_hd_deflate_init
(
&
deflater
,
side
);
printf
(
"[
\n
"
);
len
=
json_array_size
(
json
);
for
(
i
=
0
;
i
<
len
;
++
i
)
{
...
...
@@ -130,7 +139,7 @@ static int perform(nghttp2_hd_side side)
i
);
continue
;
}
if
(
deflate_hd_json
(
obj
,
&
deflater
,
i
)
!=
0
)
{
if
(
deflate_hd_json
(
obj
,
deflater
,
i
)
!=
0
)
{
continue
;
}
if
(
i
+
1
<
len
)
{
...
...
@@ -138,18 +147,15 @@ static int perform(nghttp2_hd_side side)
}
}
printf
(
"]
\n
"
);
nghttp2_hd_deflate_free
(
&
deflater
);
json_decref
(
json
);
return
0
;
}
static
int
perform_from_http1text
(
nghttp2_hd_
side
side
)
static
int
perform_from_http1text
(
nghttp2_hd_
context
*
deflater
)
{
char
line
[
1
<<
14
];
nghttp2_nv
nva
[
256
];
nghttp2_hd_context
deflater
;
int
seq
=
0
;
nghttp2_hd_deflate_init
(
&
deflater
,
side
);
printf
(
"[
\n
"
);
for
(;;)
{
size_t
nvlen
=
0
;
...
...
@@ -187,9 +193,8 @@ static int perform_from_http1text(nghttp2_hd_side side)
++
nvlen
;
inputlen
+=
nv
->
namelen
+
nv
->
valuelen
;
}
nghttp2_nv_array_sort
(
nva
,
nvlen
);
deflate_hd
(
&
deflater
,
nva
,
nvlen
,
inputlen
,
seq
);
deflate_hd
(
deflater
,
nva
,
nvlen
,
inputlen
,
seq
);
for
(
i
=
0
;
i
<
nvlen
;
++
i
)
{
free
(
nva
[
i
].
name
);
...
...
@@ -200,14 +205,13 @@ static int perform_from_http1text(nghttp2_hd_side side)
++
seq
;
}
printf
(
"]
\n
"
);
nghttp2_hd_deflate_free
(
&
deflater
);
return
0
;
}
static
void
print_help
(
void
)
{
printf
(
"HPACK-draft-04 header compressor
\n
"
"Usage: deflatehd [
-r
] < INPUT
\n
"
"Usage: deflatehd [
OPTIONS
] < INPUT
\n
"
"
\n
"
"Reads JSON array or HTTP/1-style header fields from stdin and
\n
"
"outputs deflated header block in JSON array.
\n
"
...
...
@@ -254,35 +258,75 @@ static void print_help(void)
" request.
\n
"
" -t, --http1text Use HTTP/1 style header field text as input.
\n
"
" Each header set is delimited by single empty
\n
"
" line.
\n
"
);
" line.
\n
"
" -s, --table-size=<N>
\n
"
" Set dynamic table size. This value is the
\n
"
" buffer size the decoder uses. In the HPACK
\n
"
" specification, this value is denoted by
\n
"
" SETTINGS_HEADER_TABLE_SIZE.
\n
"
" Default: 4096
\n
"
" -S, --local-table-size=<N>
\n
"
" Set effective dynamic table size when
\n
"
" encoding headers. Although a decoder uses
\n
"
" the value specified in -s option, encoder
\n
"
" can use smaller buffer size than that. This
\n
"
" option specifies it. Therefore it is
\n
"
" meaningless to specify the value equals to
\n
"
" or greater than the value given in -s
\n
"
" option.
\n
"
" Default: 4096
\n
"
);
}
static
struct
option
long_options
[]
=
{
{
"response"
,
no_argument
,
NULL
,
'r'
},
{
"http1text"
,
no_argument
,
NULL
,
't'
},
{
"table-size"
,
required_argument
,
NULL
,
's'
},
{
"local-table-size"
,
required_argument
,
NULL
,
'S'
},
{
NULL
,
0
,
NULL
,
0
}
};
int
main
(
int
argc
,
char
**
argv
)
{
nghttp2_hd_side
side
=
NGHTTP2_HD_SIDE_REQUEST
;
int
http1text
=
0
;
nghttp2_hd_context
deflater
;
char
*
end
;
config
.
side
=
NGHTTP2_HD_SIDE_REQUEST
;
config
.
table_size
=
NGHTTP2_HD_DEFAULT_MAX_BUFFER_SIZE
;
config
.
local_table_size
=
NGHTTP2_HD_DEFAULT_LOCAL_MAX_BUFFER_SIZE
;
config
.
http1text
=
0
;
while
(
1
)
{
int
option_index
=
0
;
int
c
=
getopt_long
(
argc
,
argv
,
"
hr
t"
,
long_options
,
&
option_index
);
int
c
=
getopt_long
(
argc
,
argv
,
"
S:hrs:
t"
,
long_options
,
&
option_index
);
if
(
c
==
-
1
)
{
break
;
}
switch
(
c
)
{
case
'r'
:
/* --response */
side
=
NGHTTP2_HD_SIDE_RESPONSE
;
config
.
side
=
NGHTTP2_HD_SIDE_RESPONSE
;
break
;
case
'h'
:
print_help
();
exit
(
EXIT_SUCCESS
);
case
't'
:
http1text
=
1
;
/* --http1text */
config
.
http1text
=
1
;
break
;
case
's'
:
/* --table-size */
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'
:
/* --local-table-size */
config
.
local_table_size
=
strtoul
(
optarg
,
&
end
,
10
);
if
(
errno
==
ERANGE
||
*
end
!=
'\0'
)
{
fprintf
(
stderr
,
"-S: Bad option value
\n
"
);
exit
(
EXIT_FAILURE
);
}
break
;
case
'?'
:
exit
(
EXIT_FAILURE
);
...
...
@@ -290,10 +334,13 @@ int main(int argc, char **argv)
break
;
}
}
if
(
http1text
)
{
perform_from_http1text
(
side
);
nghttp2_hd_deflate_init2
(
&
deflater
,
config
.
side
,
config
.
local_table_size
);
nghttp2_hd_change_table_size
(
&
deflater
,
config
.
table_size
);
if
(
config
.
http1text
)
{
perform_from_http1text
(
&
deflater
);
}
else
{
perform
(
side
);
perform
(
&
deflater
);
}
nghttp2_hd_deflate_free
(
&
deflater
);
return
0
;
}
hdtest/inflatehd.c
View file @
495788df
...
...
@@ -3,12 +3,21 @@
#include <unistd.h>
#include <getopt.h>
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <jansson.h>
#include "nghttp2_hd.h"
#include "nghttp2_frame.h"
typedef
struct
{
nghttp2_hd_side
side
;
size_t
table_size
;
}
inflate_config
;
static
inflate_config
config
;
static
uint8_t
to_ud
(
char
c
)
{
if
(
c
>=
'A'
&&
c
<=
'Z'
)
{
...
...
@@ -85,7 +94,7 @@ static int inflate_hd(json_t *obj, nghttp2_hd_context *inflater, int seq)
return
0
;
}
static
int
perform
(
nghttp2_hd_side
side
)
static
int
perform
()
{
nghttp2_hd_context
inflater
;
size_t
i
;
...
...
@@ -98,7 +107,8 @@ static int perform(nghttp2_hd_side side)
fprintf
(
stderr
,
"JSON loading failed
\n
"
);
exit
(
EXIT_FAILURE
);
}
nghttp2_hd_inflate_init
(
&
inflater
,
side
);
nghttp2_hd_inflate_init
(
&
inflater
,
config
.
side
);
nghttp2_hd_change_table_size
(
&
inflater
,
config
.
table_size
);
printf
(
"[
\n
"
);
len
=
json_array_size
(
json
);
for
(
i
=
0
;
i
<
len
;
++
i
)
{
...
...
@@ -123,7 +133,9 @@ static int perform(nghttp2_hd_side side)
static
void
print_help
(
void
)
{
printf
(
"Usage: inflatehd [-r] < INPUT
\n\n
"
printf
(
"HPACK-draft-04 header decompressor
\n
"
"Usage: inflatehd [OPTIONS] < INPUT
\n
"
"
\n
"
"Reads JSON array from stdin and outputs inflated name/value pairs
\n
"
"in JSON array.
\n
"
"The element of input array must be a JSON object. Each object must
\n
"
...
...
@@ -141,37 +153,54 @@ static void print_help(void)
"
\n
"
"OPTIONS:
\n
"
" -r, --response Use response compression context instead of
\n
"
" request.
\n
"
);
" request.
\n
"
" -s, --table-size=<N>
\n
"
" Set dynamic table size. This value is the
\n
"
" buffer size the decoder uses. In the HPACK
\n
"
" specification, this value is denoted by
\n
"
" SETTINGS_HEADER_TABLE_SIZE.
\n
"
" Default: 4096
\n
"
);
}
static
struct
option
long_options
[]
=
{
{
"response"
,
no_argument
,
NULL
,
'r'
},
{
"table-size"
,
required_argument
,
NULL
,
's'
},
{
NULL
,
0
,
NULL
,
0
}
};
int
main
(
int
argc
,
char
**
argv
)
{
nghttp2_hd_side
side
=
NGHTTP2_HD_SIDE_REQUEST
;
char
*
end
;
config
.
side
=
NGHTTP2_HD_SIDE_REQUEST
;
config
.
table_size
=
NGHTTP2_HD_DEFAULT_MAX_BUFFER_SIZE
;
while
(
1
)
{
int
option_index
=
0
;
int
c
=
getopt_long
(
argc
,
argv
,
"hr"
,
long_options
,
&
option_index
);
int
c
=
getopt_long
(
argc
,
argv
,
"hr
s:
"
,
long_options
,
&
option_index
);
if
(
c
==
-
1
)
{
break
;
}
switch
(
c
)
{
case
'r'
:
/* --response */
side
=
NGHTTP2_HD_SIDE_RESPONSE
;
config
.
side
=
NGHTTP2_HD_SIDE_RESPONSE
;
break
;
case
'h'
:
print_help
();
exit
(
EXIT_SUCCESS
);
case
's'
:
/* --table-size */
config
.
table_size
=
strtoul
(
optarg
,
&
end
,
10
);
if
(
errno
==
ERANGE
||
*
end
!=
'\0'
)
{
fprintf
(
stderr
,
"-s: Bad option value
\n
"
);
exit
(
EXIT_FAILURE
);
}
break
;
case
'?'
:
exit
(
EXIT_FAILURE
);
default:
break
;
}
}
perform
(
side
);
perform
();
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment