protocol-hpack 1.4.3 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/protocol/hpack/compressor.rb +2 -1
- data/lib/protocol/hpack/context.rb +46 -18
- data/lib/protocol/hpack/decompressor.rb +3 -1
- data/lib/protocol/hpack/huffman.rb +7 -4
- data/lib/protocol/hpack/version.rb +1 -1
- data/license.md +2 -0
- data/readme.md +8 -8
- data/tasks/huffman.rb +6 -5
- data.tar.gz.sig +0 -0
- metadata +7 -4
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d664c70ae90134d28bf5491fe5f46612ce17292d8ebdc06daba9e423459501e
|
4
|
+
data.tar.gz: 0ede73ffcfb63a755022f3212309ce6ce4a74dcebd819f0287f8cf610a17fbee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a194f5bbdfdbb5552f0ca6216b9cbb314bb5590a10316d51f99578961ebd3247bfa3aea6f3f8430f0e2f34ec89e9a18574c7080988f5cfde571b58ed8d6b143e
|
7
|
+
data.tar.gz: e11f0747b74859d27a2834350e46c49ea573e71f772687b387d6b4e4d1fd6b3033bc2c99537961fe2c59944e0acb2e0aeb78c0d7a9dbeb681cb04391d7e0ebb2
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -11,6 +11,7 @@
|
|
11
11
|
# Copyright, 2018, by Kenichi Nakamura.
|
12
12
|
# Copyright, 2019, by Jingyi Chen.
|
13
13
|
# Copyright, 2020, by Justin Mazzocchi.
|
14
|
+
# Copyright, 2024, by Nathan Froyd.
|
14
15
|
|
15
16
|
require_relative 'context'
|
16
17
|
require_relative 'huffman'
|
@@ -118,7 +119,7 @@ module Protocol
|
|
118
119
|
# @return [String] binary string
|
119
120
|
def write_string(string, huffman = self.huffman)
|
120
121
|
if huffman != :never
|
121
|
-
encoded = Huffman.
|
122
|
+
encoded = Huffman.encode(string)
|
122
123
|
|
123
124
|
if huffman == :shorter and encoded.bytesize >= string.bytesize
|
124
125
|
encoded = nil
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
4
|
# Copyright, 2018-2024, by Samuel Williams.
|
5
|
+
# Copyright, 2024, by Maruth Goyal.
|
6
|
+
# Copyright, 2024, by Nathan Froyd.
|
5
7
|
|
6
8
|
require_relative 'huffman'
|
7
9
|
|
@@ -94,7 +96,20 @@ module Protocol
|
|
94
96
|
["via", ""],
|
95
97
|
["www-authenticate", ""],
|
96
98
|
].each(&:freeze).freeze
|
97
|
-
|
99
|
+
|
100
|
+
STATIC_EXACT_LOOKUP = {}
|
101
|
+
STATIC_NAME_LOOKUP = {}
|
102
|
+
|
103
|
+
STATIC_TABLE.each_with_index do |(name, value), i|
|
104
|
+
exact_header_values = (STATIC_EXACT_LOOKUP[name] ||= [])
|
105
|
+
exact_header_values << [value, i]
|
106
|
+
STATIC_NAME_LOOKUP[name] = i if STATIC_NAME_LOOKUP[name].nil?
|
107
|
+
end
|
108
|
+
|
109
|
+
STATIC_EXACT_LOOKUP.each {|k, v| v.freeze}
|
110
|
+
STATIC_EXACT_LOOKUP.freeze
|
111
|
+
STATIC_NAME_LOOKUP.freeze
|
112
|
+
|
98
113
|
# Initializes compression context with appropriate client/server defaults and maximum size of the dynamic table.
|
99
114
|
#
|
100
115
|
# @param table [Array] Table of header key-value pairs.
|
@@ -233,29 +248,42 @@ module Protocol
|
|
233
248
|
# :static Use static table only.
|
234
249
|
# :all Use all of them.
|
235
250
|
#
|
236
|
-
# @param
|
251
|
+
# @param name [String]
|
252
|
+
# @param value [String]
|
237
253
|
# @return [Hash] command
|
238
|
-
def add_command(
|
254
|
+
def add_command(name, value)
|
239
255
|
exact = nil
|
240
256
|
name_only = nil
|
241
257
|
|
242
|
-
if
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
258
|
+
if @index == :all || @index == :static
|
259
|
+
if (values_and_indices = STATIC_EXACT_LOOKUP[name])
|
260
|
+
values_and_indices.each do |known_value, index|
|
261
|
+
if value == known_value
|
262
|
+
exact = index
|
263
|
+
break
|
264
|
+
end
|
249
265
|
end
|
266
|
+
|
267
|
+
needs_name_lookup = exact.nil?
|
268
|
+
else
|
269
|
+
needs_name_lookup = true
|
270
|
+
end
|
271
|
+
|
272
|
+
if needs_name_lookup && (static_value = STATIC_NAME_LOOKUP[name])
|
273
|
+
name_only = static_value
|
250
274
|
end
|
251
275
|
end
|
252
|
-
|
276
|
+
|
277
|
+
if @index == :all && !exact
|
253
278
|
@table.each_index do |i|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
279
|
+
entry = @table[i]
|
280
|
+
if entry.first == name
|
281
|
+
if entry.last == value
|
282
|
+
exact ||= i + STATIC_TABLE.size
|
283
|
+
break
|
284
|
+
else
|
285
|
+
name_only ||= i + STATIC_TABLE.size
|
286
|
+
end
|
259
287
|
end
|
260
288
|
end
|
261
289
|
end
|
@@ -263,9 +291,9 @@ module Protocol
|
|
263
291
|
if exact
|
264
292
|
{name: exact, type: :indexed}
|
265
293
|
elsif name_only
|
266
|
-
{name: name_only, value:
|
294
|
+
{name: name_only, value: value, type: :incremental}
|
267
295
|
else
|
268
|
-
{name:
|
296
|
+
{name: name, value: value, type: :incremental}
|
269
297
|
end
|
270
298
|
end
|
271
299
|
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
4
|
# Copyright, 2018-2024, by Samuel Williams.
|
5
|
+
# Copyright, 2024, by Maruth Goyal.
|
6
|
+
# Copyright, 2024, by Nathan Froyd.
|
5
7
|
|
6
8
|
require_relative 'context'
|
7
9
|
require_relative 'huffman'
|
@@ -88,7 +90,7 @@ module Protocol
|
|
88
90
|
|
89
91
|
raise CompressionError, "Invalid string length, got #{string.bytesize}, expecting #{length}!" unless string.bytesize == length
|
90
92
|
|
91
|
-
string = Huffman.
|
93
|
+
string = Huffman.decode(string) if huffman
|
92
94
|
|
93
95
|
return string.force_encoding(Encoding::UTF_8)
|
94
96
|
end
|
@@ -6,6 +6,7 @@
|
|
6
6
|
# Copyright, 2015, by Tamir Duberstein.
|
7
7
|
# Copyright, 2018-2024, by Samuel Williams.
|
8
8
|
# Copyright, 2022, by Daniel Morrison.
|
9
|
+
# Copyright, 2024, by Nathan Froyd.
|
9
10
|
|
10
11
|
require_relative 'huffman/machine'
|
11
12
|
require_relative 'error'
|
@@ -22,7 +23,7 @@ module Protocol
|
|
22
23
|
#
|
23
24
|
# @param str [String]
|
24
25
|
# @return [String] binary string
|
25
|
-
def encode(str)
|
26
|
+
def self.encode(str)
|
26
27
|
bitstring = str.each_byte.map {|chr| ENCODE_TABLE[chr]}.join
|
27
28
|
bitstring << '1' * ((8 - bitstring.size) % 8)
|
28
29
|
[bitstring].pack('B*')
|
@@ -33,14 +34,15 @@ module Protocol
|
|
33
34
|
# @param buf [Buffer]
|
34
35
|
# @return [String] binary string
|
35
36
|
# @raise [CompressionError] when Huffman coded string is malformed
|
36
|
-
def decode(buffer)
|
37
|
+
def self.decode(buffer)
|
37
38
|
emit = String.new.b
|
38
39
|
state = 0 # start state
|
39
40
|
|
40
41
|
mask = (1 << BITS_AT_ONCE) - 1
|
41
42
|
buffer.each_byte do |c|
|
42
|
-
|
43
|
-
|
43
|
+
shift = BITS_AT_ONCE
|
44
|
+
while shift >= 0
|
45
|
+
branch = (c >> shift) & mask
|
44
46
|
|
45
47
|
# MACHINE[state] = [final, [transitions]]
|
46
48
|
# [final] unfinished bits so far are prefix of the EOS code.
|
@@ -52,6 +54,7 @@ module Protocol
|
|
52
54
|
raise CompressionError, 'Huffman decode error (EOS found)' if value == EOS
|
53
55
|
|
54
56
|
emit << value.chr if value
|
57
|
+
shift -= BITS_AT_ONCE
|
55
58
|
end
|
56
59
|
end
|
57
60
|
# Check whether partial input is correctly filled
|
data/license.md
CHANGED
@@ -15,6 +15,8 @@ Copyright, 2020, by Olle Jonsson.
|
|
15
15
|
Copyright, 2020, by Justin Mazzocchi.
|
16
16
|
Copyright, 2022, by Daniel Morrison.
|
17
17
|
Copyright, 2022, by Felix Yan.
|
18
|
+
Copyright, 2024, by Maruth Goyal.
|
19
|
+
Copyright, 2024, by Nathan Froyd.
|
18
20
|
|
19
21
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
20
22
|
of this software and associated documentation files (the "Software"), to deal
|
data/readme.md
CHANGED
@@ -10,6 +10,11 @@ Please see the [project documentation](https://socketry.github.io/protocol-hpack
|
|
10
10
|
|
11
11
|
- [Getting Started](https://socketry.github.io/protocol-hpack/guides/getting-started/index) - This guide explains how to use the `protocol-hpack` gem to compress and decompress HTTP/2 headers using HPACK.
|
12
12
|
|
13
|
+
## See Also
|
14
|
+
|
15
|
+
- [protocol-http2](https://github.com/socketry/protocol-http2) - Provides an HTTP/2 client and server implementation.
|
16
|
+
- [async-http](https://github.com/socketry/async-http) - Provides a complete HTTP client and server implementation on top of Async.
|
17
|
+
|
13
18
|
## Contributing
|
14
19
|
|
15
20
|
We welcome contributions to this project.
|
@@ -22,13 +27,8 @@ We welcome contributions to this project.
|
|
22
27
|
|
23
28
|
### Developer Certificate of Origin
|
24
29
|
|
25
|
-
|
30
|
+
In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
|
26
31
|
|
27
|
-
###
|
28
|
-
|
29
|
-
This project is governed by the [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
|
30
|
-
|
31
|
-
## See Also
|
32
|
+
### Community Guidelines
|
32
33
|
|
33
|
-
|
34
|
-
- [async-http](https://github.com/socketry/async-http) - Provides a complete HTTP client and server implementation on top of Async.
|
34
|
+
This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.
|
data/tasks/huffman.rb
CHANGED
@@ -6,13 +6,14 @@
|
|
6
6
|
# Copyright, 2015, by Ilya Grigorik.
|
7
7
|
# Copyright, 2016, by George Ulmer.
|
8
8
|
# Copyright, 2018-2024, by Samuel Williams.
|
9
|
+
# Copyright, 2024, by Nathan Froyd.
|
9
10
|
|
10
|
-
require_relative '../lib/
|
11
|
+
require_relative '../lib/protocol/hpack/huffman'
|
11
12
|
|
12
13
|
require 'set'
|
13
14
|
|
14
15
|
module Huffman
|
15
|
-
BITS_AT_ONCE =
|
16
|
+
BITS_AT_ONCE = Protocol::HPACK::Huffman::BITS_AT_ONCE
|
16
17
|
EOS = 256
|
17
18
|
|
18
19
|
class Node
|
@@ -49,7 +50,7 @@ module Huffman
|
|
49
50
|
|
50
51
|
def self.generate_tree
|
51
52
|
@root = new(0)
|
52
|
-
|
53
|
+
Protocol::HPACK::Huffman::CODES.each_with_index do |c, chr|
|
53
54
|
code, len = c
|
54
55
|
@root.add(code, len, chr)
|
55
56
|
end
|
@@ -71,7 +72,7 @@ module Huffman
|
|
71
72
|
|
72
73
|
(1 << BITS_AT_ONCE).times do |input|
|
73
74
|
n = node
|
74
|
-
emit = ''
|
75
|
+
emit = +''
|
75
76
|
(BITS_AT_ONCE - 1).downto(0) do |i|
|
76
77
|
bit = (input & (1 << i)).zero? ? 0 : 1
|
77
78
|
n = n.next[bit]
|
@@ -107,7 +108,7 @@ module Huffman
|
|
107
108
|
id += 1
|
108
109
|
end
|
109
110
|
|
110
|
-
File.open(File.expand_path('../lib/
|
111
|
+
File.open(File.expand_path('../lib/protocol/hpack/huffman/machine.rb', File.dirname(__FILE__)), 'w') do |f|
|
111
112
|
f.print <<HEADER
|
112
113
|
# frozen_string_literal: true
|
113
114
|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protocol-hpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
- Ilya Grigorik
|
9
9
|
- Tamir Duberstein
|
10
|
+
- Nathan Froyd
|
10
11
|
- Kaoru Maeda
|
11
12
|
- Tiago Cardoso
|
12
13
|
- Byron Formwalt
|
@@ -18,6 +19,7 @@ authors:
|
|
18
19
|
- Justin Mazzocchi
|
19
20
|
- Kenichi Nakamura
|
20
21
|
- Kien Nguyen Trung
|
22
|
+
- Maruth Goyal
|
21
23
|
- Olle Jonsson
|
22
24
|
autorequire:
|
23
25
|
bindir: bin
|
@@ -51,7 +53,7 @@ cert_chain:
|
|
51
53
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
52
54
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
53
55
|
-----END CERTIFICATE-----
|
54
|
-
date: 2024-
|
56
|
+
date: 2024-07-28 00:00:00.000000000 Z
|
55
57
|
dependencies: []
|
56
58
|
description:
|
57
59
|
email:
|
@@ -76,6 +78,7 @@ licenses:
|
|
76
78
|
- MIT
|
77
79
|
metadata:
|
78
80
|
documentation_uri: https://socketry.github.io/protocol-hpack/
|
81
|
+
source_code_uri: https://github.com/socketry/http-hpack.git
|
79
82
|
post_install_message:
|
80
83
|
rdoc_options: []
|
81
84
|
require_paths:
|
@@ -84,14 +87,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
87
|
requirements:
|
85
88
|
- - ">="
|
86
89
|
- !ruby/object:Gem::Version
|
87
|
-
version: '3.
|
90
|
+
version: '3.1'
|
88
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
92
|
requirements:
|
90
93
|
- - ">="
|
91
94
|
- !ruby/object:Gem::Version
|
92
95
|
version: '0'
|
93
96
|
requirements: []
|
94
|
-
rubygems_version: 3.5.
|
97
|
+
rubygems_version: 3.5.11
|
95
98
|
signing_key:
|
96
99
|
specification_version: 4
|
97
100
|
summary: A compresssor and decompressor for HTTP/2's HPACK format.
|
metadata.gz.sig
CHANGED
Binary file
|