Skip to content

Commit 790cf6f

Browse files
weissiLukasa
authored andcommitted
remove hpack-test-case submodule (#156)
Motivation: Submodules can cause trouble with mirrored git setups because they can't be easily mirrored through SwiftPM's mirror support. Modification: Remove the hpack-test-case submodule and add as files. Result: Easier to mirror.
1 parent 58bf1c9 commit 790cf6f

File tree

420 files changed

+1788888
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

420 files changed

+1788888
-6
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "hpack-test-case"]
2-
path = hpack-test-case
3-
url = https://github.com/http2jp/hpack-test-case.git

Tests/NIOHPACKTests/HPACKIntegrationTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ class HPACKIntegrationTests : XCTestCase {
2222
let myURL = URL(fileURLWithPath: #file, isDirectory: false)
2323
let result: URL
2424
if #available(OSX 10.11, iOS 9.0, *) {
25-
result = URL(fileURLWithPath: "../../hpack-test-case", isDirectory: true, relativeTo: myURL).absoluteURL
25+
result = URL(fileURLWithPath: "../hpack-test-case", isDirectory: true, relativeTo: myURL).absoluteURL
2626
} else {
2727
// Fallback on earlier versions
28-
result = URL(string: "../../hpack-test-case", relativeTo: myURL)!.absoluteURL
28+
result = URL(string: "../hpack-test-case", relativeTo: myURL)!.absoluteURL
2929
}
3030
return result
3131
}()

Tests/hpack-test-case/README.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# hpack-test-case
2+
3+
## Spec
4+
5+
HPACK: Header Compression for HTTP/2
6+
https://tools.ietf.org/html/rfc7541
7+
8+
9+
## Directory
10+
11+
The ```raw-data``` directory has original stories of header data in
12+
json.
13+
14+
Other than ```raw-data``` directory, the HPACK implementations have
15+
their own directories to store the result of its encoder.
16+
17+
You can perform interoperability testing for your implementation with
18+
them.
19+
20+
## File Name
21+
22+
Each json in story-#{n}.json is story case and shares compression
23+
context. Each story is either series of requests or responses.
24+
25+
## JSON Format
26+
27+
Each json has:
28+
29+
- description: general description of encoding strategy or implementation.
30+
- cases: array of test cases.
31+
- seqno: a sequence number. 0 origin.
32+
- header_table_size: the header table size sent in SETTINGS_HEADER_TABLE_SIZE and ACKed just before this case. The first case should contain this field. If omitted, the default value, 4,096, is used.
33+
- wire: encoded wire data in hex string.
34+
- headers: decoded http header in hash.
35+
36+
To test the decoder implementation, for each story file, for each case
37+
in ```cases``` in the order they appear, decode compressed header
38+
block in ```wire``` and verify the result against the header set in
39+
```headers```. Please note that elements in ```cases``` share the same
40+
compression context.
41+
42+
To test the encoder implementation, generate json story files by
43+
encoding header sets in ```headers```. Using json files in
44+
```raw-data``` is handy. Then use your decoder to verify that it can
45+
successfully decode the compressed header block. If you can play with
46+
other HPACK decoder implementations, try decoding your encoded data
47+
with them. If there is any mismatch, then there must be a bug in
48+
somewhere either encoder or decoder, or both.
49+
50+
```js
51+
{
52+
"description": "Encoded request headers with Literal without index only.",
53+
"cases": [
54+
{
55+
"seqno": 0,
56+
"header_table_size": 4096,
57+
"wire": "1234567890abcdef",
58+
"headers": [
59+
{ ":method": "GET" },
60+
{ ":scheme": "http" },
61+
{ ":authority": "example.com" },
62+
{ ":path": "/" },
63+
{ "x-my-header": "value1,value2" }
64+
]
65+
},
66+
.....
67+
]
68+
}
69+
```
70+
71+
## Original Data
72+
73+
These Header Data are converted from https://github.com/http2/http_samples
74+
75+
76+
## Compression Ratio
77+
78+
https://github.com/http2jp/hpack-test-case/wiki/Compression-Ratio
79+
80+
81+
## Contributor
82+
83+
- jxck
84+
- summerwind
85+
- kazu-yamamoto
86+
- tatsuhiro-t
87+
88+
89+
## License
90+
91+
The MIT License (MIT)

Tests/hpack-test-case/genratiotbl.py

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#!/usr/bin/env python
2+
#
3+
# This script takes directories which contain the hpack-test-case json
4+
# files, and calculates the compression ratio in each file and outputs
5+
# the result in table formatted in rst.
6+
#
7+
# The each directory contains the result of various HPACK compressor.
8+
#
9+
# The table is laid out so that we can see that how input header set
10+
# in one json file is compressed in each compressor.
11+
#
12+
import sys, json, os, re, argparse
13+
14+
class Stat:
15+
16+
def __init__(self, complen, srclen):
17+
self.complen = complen
18+
self.srclen = srclen
19+
20+
def compute_stat(jsdata):
21+
complen = 0
22+
srclen = 0
23+
for item in jsdata['cases']:
24+
complen += len(item['wire']) // 2
25+
srclen += \
26+
sum([len(list(x.keys())[0]) + len(list(x.values())[0]) \
27+
for x in item['headers']])
28+
return Stat(complen, srclen)
29+
30+
def format_result(r):
31+
return '{:.02f} ({}/{}) '.format(float(r.complen)/r.srclen,
32+
r.complen, r.srclen)
33+
34+
if __name__ == '__main__':
35+
ap = argparse.ArgumentParser(description='''\
36+
Generate HPACK compression ratio table in reStructuredText.
37+
38+
An output is written to stdout.
39+
''')
40+
ap.add_argument('dir', nargs='+',
41+
help='A directory containing JSON files')
42+
43+
args = ap.parse_args()
44+
45+
entries = [(os.path.basename(re.sub(r'/+$', '', p)), p) for p in args.dir]
46+
maxnamelen = 0
47+
maxstorynamelen = 0
48+
res = {}
49+
50+
stories = set()
51+
for name, ent in entries:
52+
files = [p for p in os.listdir(ent) if p.endswith('.json')]
53+
res[name] = {}
54+
maxnamelen = max(maxnamelen, len(name))
55+
for fn in files:
56+
stories.add(fn)
57+
maxstorynamelen = max(maxstorynamelen, len(fn))
58+
with open(os.path.join(ent, fn)) as f:
59+
input = f.read()
60+
rv = compute_stat(json.loads(input))
61+
res[name][fn] = rv
62+
maxnamelen = max(maxnamelen, len(format_result(rv)))
63+
stories = list(stories)
64+
stories.sort()
65+
66+
overall = []
67+
for name, _ in entries:
68+
r = Stat(0, 0)
69+
for _, stat in res[name].items():
70+
r.srclen += stat.srclen
71+
r.complen += stat.complen
72+
overall.append(r)
73+
maxnamelen = max(maxnamelen, len(format_result(r)))
74+
75+
storynameformat = '{{:{}}} '.format(maxstorynamelen)
76+
nameformat = '{{:{}}} '.format(maxnamelen)
77+
78+
79+
sys.stdout.write('''\
80+
hpack-test-case compression ratio
81+
=================================
82+
83+
The each cell has ``X (Y/Z)`` format:
84+
85+
X
86+
Y / Z
87+
Y
88+
number of bytes after compression
89+
Z
90+
number of bytes before compression
91+
92+
''')
93+
94+
def write_border():
95+
sys.stdout.write('='*maxstorynamelen)
96+
sys.stdout.write(' ')
97+
for _ in entries:
98+
sys.stdout.write('='*maxnamelen)
99+
sys.stdout.write(' ')
100+
sys.stdout.write('\n')
101+
102+
write_border()
103+
104+
sys.stdout.write(storynameformat.format('story'))
105+
for name, _ in entries:
106+
sys.stdout.write(nameformat.format(name))
107+
sys.stdout.write('\n')
108+
109+
write_border()
110+
111+
for story in stories:
112+
sys.stdout.write(storynameformat.format(story))
113+
srclen = -1
114+
for name, _ in entries:
115+
stats = res[name]
116+
if story not in stats:
117+
sys.stdout.write(nameformat.format('N/A'))
118+
continue
119+
if srclen == -1:
120+
srclen = stats[story].srclen
121+
elif srclen != stats[story].srclen:
122+
raise Exception('Bad srclen')
123+
sys.stdout.write(nameformat.format(format_result(stats[story])))
124+
sys.stdout.write('\n')
125+
126+
sys.stdout.write(storynameformat.format('Overall'))
127+
for r in overall:
128+
sys.stdout.write(nameformat.format(format_result(r)))
129+
sys.stdout.write('\n')
130+
131+
write_border()
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"description": "https://github.com/Jxck/hpack implemeted in Golang. Encoded using String Literal with Huffman, no Header/Static Table, and always start with emptied Reference Set. by Jxck.",
3+
"cases": [
4+
{
5+
"seqno": 0,
6+
"header_table_size": 4096,
7+
"wire": "0085b9495339e483c5837f0085b8824e5a4b839d29af0088b83b5339ec327d7f88f439ce75c875fa570084b958d33f8163",
8+
"headers": [
9+
{
10+
":method": "GET"
11+
},
12+
{
13+
":scheme": "http"
14+
},
15+
{
16+
":authority": "yahoo.co.jp"
17+
},
18+
{
19+
":path": "/"
20+
}
21+
]
22+
},
23+
{
24+
"seqno": 1,
25+
"header_table_size": 4096,
26+
"wire": "0085b9495339e483c5837f0085b8824e5a4b839d29af0088b83b5339ec327d7f8cf1e3c2fe8739ceb90ebf4aff0084b958d33f8163",
27+
"headers": [
28+
{
29+
":method": "GET"
30+
},
31+
{
32+
":scheme": "http"
33+
},
34+
{
35+
":authority": "www.yahoo.co.jp"
36+
},
37+
{
38+
":path": "/"
39+
}
40+
]
41+
},
42+
{
43+
"seqno": 2,
44+
"header_table_size": 4096,
45+
"wire": "0085b9495339e483c5837f0085b8824e5a4b839d29af0088b83b5339ec327d7f87eabfa35332fd2b0084b958d33f9b60d48e62a1849eb611589825353141e63ad52160b206c4f2f5d537",
46+
"headers": [
47+
{
48+
":method": "GET"
49+
},
50+
{
51+
":scheme": "http"
52+
},
53+
{
54+
":authority": "k.yimg.jp"
55+
},
56+
{
57+
":path": "/images/top/sp2/cmn/logo-ns-130528.png"
58+
}
59+
]
60+
}
61+
]
62+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"description": "https://github.com/Jxck/hpack implemeted in Golang. Encoded using String Literal with Huffman, no Header/Static Table, and always start with emptied Reference Set. by Jxck.",
3+
"cases": [
4+
{
5+
"seqno": 0,
6+
"header_table_size": 4096,
7+
"wire": "0085b8824e5a4b849d29ad1f0088b83b5339ec327d7f882f91d35d055c87a70084b958d33f81630085b9495339e483c5837f0087b505b161cc5a93879eb193aac92a13008421cfd4c587f3e7cf9f3e7c870086f2b4e5a283ff84f07b2893",
8+
"headers": [
9+
{
10+
":scheme": "https"
11+
},
12+
{
13+
":authority": "example.com"
14+
},
15+
{
16+
":path": "/"
17+
},
18+
{
19+
":method": "GET"
20+
},
21+
{
22+
"user-agent": "hpack-test"
23+
},
24+
{
25+
"cookie": "xxxxxxx1"
26+
},
27+
{
28+
"x-hello": "world"
29+
}
30+
]
31+
},
32+
{
33+
"seqno": 1,
34+
"header_table_size": 4096,
35+
"wire": "0085b8824e5a4b849d29ad1f0088b83b5339ec327d7f882f91d35d055c87a70084b958d33f81630085b9495339e483c5837f0087b505b161cc5a93879eb193aac92a13008421cfd4c587f3e7cf9f3e7c8b",
36+
"headers": [
37+
{
38+
":scheme": "https"
39+
},
40+
{
41+
":authority": "example.com"
42+
},
43+
{
44+
":path": "/"
45+
},
46+
{
47+
":method": "GET"
48+
},
49+
{
50+
"user-agent": "hpack-test"
51+
},
52+
{
53+
"cookie": "xxxxxxx2"
54+
}
55+
]
56+
}
57+
]
58+
}

0 commit comments

Comments
 (0)