rwebtransport 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +666 -666
- package/Cargo.toml +31 -31
- package/LICENSE +202 -202
- package/NOTICE +41 -41
- package/README.md +550 -550
- package/crates/echo-server/Cargo.toml +20 -20
- package/crates/echo-server/src/main.rs +666 -666
- package/crates/native/Cargo.toml +23 -23
- package/crates/native/src/config.rs +129 -129
- package/crates/native/src/driver.rs +463 -463
- package/crates/native/src/lib.rs +821 -821
- package/crates/native/src/server.rs +718 -718
- package/crates/native/src/session.rs +1191 -1191
- package/crates/native/src/tls.rs +96 -96
- package/crates/wtcore/Cargo.toml +15 -15
- package/crates/wtcore/src/h3.rs +226 -226
- package/crates/wtcore/src/lib.rs +9 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +80 -79
- package/prebuilds/darwin-arm64/rwebtransport.node +0 -0
- package/prebuilds/linux-arm64/rwebtransport.node +0 -0
- package/prebuilds/linux-x64/rwebtransport.node +0 -0
- package/prebuilds/win32-x64/rwebtransport.node +0 -0
- package/scripts/bench.mjs +180 -180
- package/scripts/build.js +67 -67
- package/scripts/postinstall.js +67 -67
- package/scripts/setup-unix.sh +129 -129
- package/scripts/setup-windows.ps1 +229 -229
- package/vendor/quiche/AGENTS.md +75 -75
- package/vendor/quiche/COPYING +23 -23
- package/vendor/quiche/Cargo.lock +1212 -1212
- package/vendor/quiche/Cargo.toml +215 -215
- package/vendor/quiche/README.md +466 -466
- package/vendor/quiche/examples/Makefile +46 -46
- package/vendor/quiche/examples/README.md +20 -20
- package/vendor/quiche/examples/cert-big.crt +90 -90
- package/vendor/quiche/examples/cert.crt +18 -18
- package/vendor/quiche/examples/cert.key +28 -28
- package/vendor/quiche/examples/client.c +343 -343
- package/vendor/quiche/examples/client.rs +281 -281
- package/vendor/quiche/examples/gen-certs.sh +15 -15
- package/vendor/quiche/examples/http3-client.c +473 -473
- package/vendor/quiche/examples/http3-client.rs +349 -349
- package/vendor/quiche/examples/http3-server.c +614 -614
- package/vendor/quiche/examples/http3-server.rs +680 -680
- package/vendor/quiche/examples/qpack-decode.rs +87 -87
- package/vendor/quiche/examples/qpack-encode.rs +88 -88
- package/vendor/quiche/examples/rootca.crt +21 -21
- package/vendor/quiche/examples/server.c +529 -529
- package/vendor/quiche/examples/server.rs +529 -529
- package/vendor/quiche/include/quiche.h +1282 -1282
- package/vendor/quiche/src/buffers.rs +105 -105
- package/vendor/quiche/src/build.rs +66 -66
- package/vendor/quiche/src/cid.rs +1079 -1079
- package/vendor/quiche/src/crypto/boringssl.rs +373 -373
- package/vendor/quiche/src/crypto/mod.rs +671 -671
- package/vendor/quiche/src/dgram.rs +118 -118
- package/vendor/quiche/src/error.rs +263 -263
- package/vendor/quiche/src/ffi.rs +2290 -2290
- package/vendor/quiche/src/flowcontrol.rs +246 -246
- package/vendor/quiche/src/frame.rs +2172 -2172
- package/vendor/quiche/src/h3/AGENTS.md +54 -54
- package/vendor/quiche/src/h3/ffi.rs +442 -442
- package/vendor/quiche/src/h3/frame.rs +1404 -1404
- package/vendor/quiche/src/h3/mod.rs +8223 -8223
- package/vendor/quiche/src/h3/qpack/decoder.rs +288 -288
- package/vendor/quiche/src/h3/qpack/encoder.rs +235 -235
- package/vendor/quiche/src/h3/qpack/mod.rs +202 -202
- package/vendor/quiche/src/h3/qpack/static_table.rs +323 -323
- package/vendor/quiche/src/h3/stream.rs +1595 -1595
- package/vendor/quiche/src/lib.rs +9556 -9556
- package/vendor/quiche/src/minmax.rs +446 -446
- package/vendor/quiche/src/packet.rs +2334 -2334
- package/vendor/quiche/src/path.rs +1374 -1374
- package/vendor/quiche/src/pmtud.rs +652 -652
- package/vendor/quiche/src/rand.rs +64 -64
- package/vendor/quiche/src/range_buf.rs +186 -186
- package/vendor/quiche/src/ranges.rs +755 -755
- package/vendor/quiche/src/recovery/AGENTS.md +80 -80
- package/vendor/quiche/src/recovery/bandwidth.rs +565 -565
- package/vendor/quiche/src/recovery/bytes_in_flight.rs +179 -179
- package/vendor/quiche/src/recovery/congestion/cubic.rs +1038 -1038
- package/vendor/quiche/src/recovery/congestion/delivery_rate.rs +514 -514
- package/vendor/quiche/src/recovery/congestion/hystart.rs +241 -241
- package/vendor/quiche/src/recovery/congestion/mod.rs +361 -361
- package/vendor/quiche/src/recovery/congestion/prr.rs +238 -238
- package/vendor/quiche/src/recovery/congestion/recovery.rs +1170 -1170
- package/vendor/quiche/src/recovery/congestion/reno.rs +291 -291
- package/vendor/quiche/src/recovery/congestion/test_sender.rs +201 -201
- package/vendor/quiche/src/recovery/gcongestion/bbr/bandwidth_sampler.rs +1947 -1947
- package/vendor/quiche/src/recovery/gcongestion/bbr/windowed_filter.rs +158 -158
- package/vendor/quiche/src/recovery/gcongestion/bbr.rs +37 -37
- package/vendor/quiche/src/recovery/gcongestion/bbr2/drain.rs +120 -120
- package/vendor/quiche/src/recovery/gcongestion/bbr2/mode.rs +318 -318
- package/vendor/quiche/src/recovery/gcongestion/bbr2/network_model.rs +784 -784
- package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_bw.rs +729 -729
- package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_rtt.rs +175 -175
- package/vendor/quiche/src/recovery/gcongestion/bbr2/startup.rs +190 -190
- package/vendor/quiche/src/recovery/gcongestion/bbr2.rs +855 -855
- package/vendor/quiche/src/recovery/gcongestion/mod.rs +275 -275
- package/vendor/quiche/src/recovery/gcongestion/pacer.rs +294 -294
- package/vendor/quiche/src/recovery/gcongestion/recovery.rs +1384 -1384
- package/vendor/quiche/src/recovery/mod.rs +3086 -3086
- package/vendor/quiche/src/recovery/rtt.rs +152 -152
- package/vendor/quiche/src/stream/mod.rs +2210 -2210
- package/vendor/quiche/src/stream/recv_buf.rs +1236 -1236
- package/vendor/quiche/src/stream/send_buf.rs +849 -849
- package/vendor/quiche/src/test_utils.rs +681 -681
- package/vendor/quiche/src/tests.rs +12922 -12922
- package/vendor/quiche/src/tls/boringssl.rs +375 -375
- package/vendor/quiche/src/tls/mod.rs +1245 -1245
- package/vendor/quiche/src/transport_params.rs +628 -628
|
@@ -1,202 +1,202 @@
|
|
|
1
|
-
// Copyright (C) 2019, Cloudflare, Inc.
|
|
2
|
-
// All rights reserved.
|
|
3
|
-
//
|
|
4
|
-
// Redistribution and use in source and binary forms, with or without
|
|
5
|
-
// modification, are permitted provided that the following conditions are
|
|
6
|
-
// met:
|
|
7
|
-
//
|
|
8
|
-
// * Redistributions of source code must retain the above copyright notice,
|
|
9
|
-
// this list of conditions and the following disclaimer.
|
|
10
|
-
//
|
|
11
|
-
// * Redistributions in binary form must reproduce the above copyright
|
|
12
|
-
// notice, this list of conditions and the following disclaimer in the
|
|
13
|
-
// documentation and/or other materials provided with the distribution.
|
|
14
|
-
//
|
|
15
|
-
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
16
|
-
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
17
|
-
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
18
|
-
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
19
|
-
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
20
|
-
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
21
|
-
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
22
|
-
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
23
|
-
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
24
|
-
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
25
|
-
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
-
|
|
27
|
-
//! HTTP/3 header compression (QPACK).
|
|
28
|
-
|
|
29
|
-
pub use encoder::encode_int;
|
|
30
|
-
pub use encoder::encode_str;
|
|
31
|
-
|
|
32
|
-
pub const INDEXED: u8 = 0b1000_0000;
|
|
33
|
-
pub const INDEXED_WITH_POST_BASE: u8 = 0b0001_0000;
|
|
34
|
-
pub const LITERAL: u8 = 0b0010_0000;
|
|
35
|
-
pub const LITERAL_WITH_NAME_REF: u8 = 0b0100_0000;
|
|
36
|
-
|
|
37
|
-
/// A specialized [`Result`] type for quiche QPACK operations.
|
|
38
|
-
///
|
|
39
|
-
/// This type is used throughout quiche's QPACK public API for any operation
|
|
40
|
-
/// that can produce an error.
|
|
41
|
-
///
|
|
42
|
-
/// [`Result`]: https://doc.rust-lang.org/std/result/enum.Result.html
|
|
43
|
-
pub type Result<T> = std::result::Result<T, Error>;
|
|
44
|
-
|
|
45
|
-
/// A QPACK error.
|
|
46
|
-
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
47
|
-
pub enum Error {
|
|
48
|
-
/// The provided buffer is too short.
|
|
49
|
-
BufferTooShort,
|
|
50
|
-
|
|
51
|
-
/// The QPACK header block's huffman encoding is invalid.
|
|
52
|
-
InvalidHuffmanEncoding,
|
|
53
|
-
|
|
54
|
-
/// The QPACK static table index provided doesn't exist.
|
|
55
|
-
InvalidStaticTableIndex,
|
|
56
|
-
|
|
57
|
-
/// The decoded QPACK header name or value is not valid.
|
|
58
|
-
InvalidHeaderValue,
|
|
59
|
-
|
|
60
|
-
/// The decoded header list exceeded the size limit.
|
|
61
|
-
HeaderListTooLarge,
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
impl std::fmt::Display for Error {
|
|
65
|
-
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
66
|
-
write!(f, "{self:?}")
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
impl std::error::Error for Error {
|
|
71
|
-
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
|
72
|
-
None
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
impl From<octets::BufferTooShortError> for Error {
|
|
77
|
-
fn from(_err: octets::BufferTooShortError) -> Self {
|
|
78
|
-
Error::BufferTooShort
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
#[cfg(test)]
|
|
83
|
-
mod tests {
|
|
84
|
-
use crate::*;
|
|
85
|
-
|
|
86
|
-
use super::*;
|
|
87
|
-
|
|
88
|
-
#[test]
|
|
89
|
-
fn encode_decode() {
|
|
90
|
-
let mut encoded = [0u8; 240];
|
|
91
|
-
|
|
92
|
-
let headers = vec![
|
|
93
|
-
h3::Header::new(b":path", b"/rsrc.php/v3/yn/r/rIPZ9Qkrdd9.png"),
|
|
94
|
-
h3::Header::new(b"accept-encoding", b"gzip, deflate, br"),
|
|
95
|
-
h3::Header::new(b"accept-language", b"en-US,en;q=0.9"),
|
|
96
|
-
h3::Header::new(b"user-agent", b"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.70 Safari/537.36"),
|
|
97
|
-
h3::Header::new(b"accept", b"image/webp,image/apng,image/*,*/*;q=0.8"),
|
|
98
|
-
h3::Header::new(b"referer", b"https://static.xx.fbcdn.net/rsrc.php/v3/yT/l/0,cross/dzXGESIlGQQ.css"),
|
|
99
|
-
h3::Header::new(b":authority", b"static.xx.fbcdn.net"),
|
|
100
|
-
h3::Header::new(b":scheme", b"https"),
|
|
101
|
-
h3::Header::new(b":method", b"GET"),
|
|
102
|
-
];
|
|
103
|
-
|
|
104
|
-
let mut enc = Encoder::new();
|
|
105
|
-
assert_eq!(enc.encode(&headers, &mut encoded), Ok(240));
|
|
106
|
-
|
|
107
|
-
let mut dec = Decoder::new();
|
|
108
|
-
assert_eq!(dec.decode(&encoded, u64::MAX), Ok(headers));
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
#[test]
|
|
112
|
-
fn lower_case() {
|
|
113
|
-
let mut encoded = [0u8; 35];
|
|
114
|
-
|
|
115
|
-
let headers_expected = vec![
|
|
116
|
-
h3::Header::new(b":status", b"200"),
|
|
117
|
-
h3::Header::new(b":path", b"/HeLlO"),
|
|
118
|
-
h3::Header::new(b"woot", b"woot"),
|
|
119
|
-
h3::Header::new(b"hello", b"WorlD"),
|
|
120
|
-
h3::Header::new(b"foo", b"BaR"),
|
|
121
|
-
];
|
|
122
|
-
|
|
123
|
-
// Header.
|
|
124
|
-
let headers_in = vec![
|
|
125
|
-
h3::Header::new(b":StAtUs", b"200"),
|
|
126
|
-
h3::Header::new(b":PaTh", b"/HeLlO"),
|
|
127
|
-
h3::Header::new(b"WooT", b"woot"),
|
|
128
|
-
h3::Header::new(b"hello", b"WorlD"),
|
|
129
|
-
h3::Header::new(b"fOo", b"BaR"),
|
|
130
|
-
];
|
|
131
|
-
|
|
132
|
-
let mut enc = Encoder::new();
|
|
133
|
-
assert_eq!(enc.encode(&headers_in, &mut encoded), Ok(35));
|
|
134
|
-
|
|
135
|
-
let mut dec = Decoder::new();
|
|
136
|
-
let headers_out = dec.decode(&encoded, u64::MAX).unwrap();
|
|
137
|
-
|
|
138
|
-
assert_eq!(headers_expected, headers_out);
|
|
139
|
-
|
|
140
|
-
// HeaderRef.
|
|
141
|
-
let headers_in = vec![
|
|
142
|
-
h3::HeaderRef::new(b":StAtUs", b"200"),
|
|
143
|
-
h3::HeaderRef::new(b":PaTh", b"/HeLlO"),
|
|
144
|
-
h3::HeaderRef::new(b"WooT", b"woot"),
|
|
145
|
-
h3::HeaderRef::new(b"hello", b"WorlD"),
|
|
146
|
-
h3::HeaderRef::new(b"fOo", b"BaR"),
|
|
147
|
-
];
|
|
148
|
-
|
|
149
|
-
let mut enc = Encoder::new();
|
|
150
|
-
assert_eq!(enc.encode(&headers_in, &mut encoded), Ok(35));
|
|
151
|
-
|
|
152
|
-
let mut dec = Decoder::new();
|
|
153
|
-
let headers_out = dec.decode(&encoded, u64::MAX).unwrap();
|
|
154
|
-
|
|
155
|
-
assert_eq!(headers_expected, headers_out);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
#[test]
|
|
159
|
-
fn lower_ascii_range() {
|
|
160
|
-
let mut encoded = [0u8; 50];
|
|
161
|
-
let mut enc = Encoder::new();
|
|
162
|
-
|
|
163
|
-
// Indexed name with literal value
|
|
164
|
-
let headers1 = vec![h3::Header::new(b"location", b" ")];
|
|
165
|
-
assert_eq!(enc.encode(&headers1, &mut encoded), Ok(19));
|
|
166
|
-
|
|
167
|
-
// Literal name and value
|
|
168
|
-
let headers2 = vec![h3::Header::new(b"a", b"")];
|
|
169
|
-
assert_eq!(enc.encode(&headers2, &mut encoded), Ok(20));
|
|
170
|
-
|
|
171
|
-
let headers3 = vec![h3::Header::new(b" ", b"hello")];
|
|
172
|
-
assert_eq!(enc.encode(&headers3, &mut encoded), Ok(24));
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
#[test]
|
|
176
|
-
fn extended_ascii_range() {
|
|
177
|
-
let mut encoded = [0u8; 50];
|
|
178
|
-
let mut enc = Encoder::new();
|
|
179
|
-
|
|
180
|
-
let name = b"location";
|
|
181
|
-
let value = "£££££££££££££££";
|
|
182
|
-
|
|
183
|
-
// Indexed name with literal value
|
|
184
|
-
let headers1 = vec![h3::Header::new(name, value.as_bytes())];
|
|
185
|
-
assert_eq!(enc.encode(&headers1, &mut encoded), Ok(34));
|
|
186
|
-
|
|
187
|
-
// Literal name and value
|
|
188
|
-
let value = "ððððððððððððððð";
|
|
189
|
-
let headers2 = vec![h3::Header::new(b"a", value.as_bytes())];
|
|
190
|
-
assert_eq!(enc.encode(&headers2, &mut encoded), Ok(35));
|
|
191
|
-
|
|
192
|
-
let headers3 = vec![h3::Header::new(value.as_bytes(), b"hello")];
|
|
193
|
-
assert_eq!(enc.encode(&headers3, &mut encoded), Ok(39));
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
pub use decoder::Decoder;
|
|
198
|
-
pub use encoder::Encoder;
|
|
199
|
-
|
|
200
|
-
mod decoder;
|
|
201
|
-
mod encoder;
|
|
202
|
-
mod static_table;
|
|
1
|
+
// Copyright (C) 2019, Cloudflare, Inc.
|
|
2
|
+
// All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
// Redistribution and use in source and binary forms, with or without
|
|
5
|
+
// modification, are permitted provided that the following conditions are
|
|
6
|
+
// met:
|
|
7
|
+
//
|
|
8
|
+
// * Redistributions of source code must retain the above copyright notice,
|
|
9
|
+
// this list of conditions and the following disclaimer.
|
|
10
|
+
//
|
|
11
|
+
// * Redistributions in binary form must reproduce the above copyright
|
|
12
|
+
// notice, this list of conditions and the following disclaimer in the
|
|
13
|
+
// documentation and/or other materials provided with the distribution.
|
|
14
|
+
//
|
|
15
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
16
|
+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
17
|
+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
18
|
+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
19
|
+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
20
|
+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
21
|
+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
22
|
+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
23
|
+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
24
|
+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
25
|
+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
+
|
|
27
|
+
//! HTTP/3 header compression (QPACK).
|
|
28
|
+
|
|
29
|
+
pub use encoder::encode_int;
|
|
30
|
+
pub use encoder::encode_str;
|
|
31
|
+
|
|
32
|
+
pub const INDEXED: u8 = 0b1000_0000;
|
|
33
|
+
pub const INDEXED_WITH_POST_BASE: u8 = 0b0001_0000;
|
|
34
|
+
pub const LITERAL: u8 = 0b0010_0000;
|
|
35
|
+
pub const LITERAL_WITH_NAME_REF: u8 = 0b0100_0000;
|
|
36
|
+
|
|
37
|
+
/// A specialized [`Result`] type for quiche QPACK operations.
|
|
38
|
+
///
|
|
39
|
+
/// This type is used throughout quiche's QPACK public API for any operation
|
|
40
|
+
/// that can produce an error.
|
|
41
|
+
///
|
|
42
|
+
/// [`Result`]: https://doc.rust-lang.org/std/result/enum.Result.html
|
|
43
|
+
pub type Result<T> = std::result::Result<T, Error>;
|
|
44
|
+
|
|
45
|
+
/// A QPACK error.
|
|
46
|
+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
47
|
+
pub enum Error {
|
|
48
|
+
/// The provided buffer is too short.
|
|
49
|
+
BufferTooShort,
|
|
50
|
+
|
|
51
|
+
/// The QPACK header block's huffman encoding is invalid.
|
|
52
|
+
InvalidHuffmanEncoding,
|
|
53
|
+
|
|
54
|
+
/// The QPACK static table index provided doesn't exist.
|
|
55
|
+
InvalidStaticTableIndex,
|
|
56
|
+
|
|
57
|
+
/// The decoded QPACK header name or value is not valid.
|
|
58
|
+
InvalidHeaderValue,
|
|
59
|
+
|
|
60
|
+
/// The decoded header list exceeded the size limit.
|
|
61
|
+
HeaderListTooLarge,
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
impl std::fmt::Display for Error {
|
|
65
|
+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
66
|
+
write!(f, "{self:?}")
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
impl std::error::Error for Error {
|
|
71
|
+
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
|
72
|
+
None
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
impl From<octets::BufferTooShortError> for Error {
|
|
77
|
+
fn from(_err: octets::BufferTooShortError) -> Self {
|
|
78
|
+
Error::BufferTooShort
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
#[cfg(test)]
|
|
83
|
+
mod tests {
|
|
84
|
+
use crate::*;
|
|
85
|
+
|
|
86
|
+
use super::*;
|
|
87
|
+
|
|
88
|
+
#[test]
|
|
89
|
+
fn encode_decode() {
|
|
90
|
+
let mut encoded = [0u8; 240];
|
|
91
|
+
|
|
92
|
+
let headers = vec![
|
|
93
|
+
h3::Header::new(b":path", b"/rsrc.php/v3/yn/r/rIPZ9Qkrdd9.png"),
|
|
94
|
+
h3::Header::new(b"accept-encoding", b"gzip, deflate, br"),
|
|
95
|
+
h3::Header::new(b"accept-language", b"en-US,en;q=0.9"),
|
|
96
|
+
h3::Header::new(b"user-agent", b"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.70 Safari/537.36"),
|
|
97
|
+
h3::Header::new(b"accept", b"image/webp,image/apng,image/*,*/*;q=0.8"),
|
|
98
|
+
h3::Header::new(b"referer", b"https://static.xx.fbcdn.net/rsrc.php/v3/yT/l/0,cross/dzXGESIlGQQ.css"),
|
|
99
|
+
h3::Header::new(b":authority", b"static.xx.fbcdn.net"),
|
|
100
|
+
h3::Header::new(b":scheme", b"https"),
|
|
101
|
+
h3::Header::new(b":method", b"GET"),
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
let mut enc = Encoder::new();
|
|
105
|
+
assert_eq!(enc.encode(&headers, &mut encoded), Ok(240));
|
|
106
|
+
|
|
107
|
+
let mut dec = Decoder::new();
|
|
108
|
+
assert_eq!(dec.decode(&encoded, u64::MAX), Ok(headers));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
#[test]
|
|
112
|
+
fn lower_case() {
|
|
113
|
+
let mut encoded = [0u8; 35];
|
|
114
|
+
|
|
115
|
+
let headers_expected = vec![
|
|
116
|
+
h3::Header::new(b":status", b"200"),
|
|
117
|
+
h3::Header::new(b":path", b"/HeLlO"),
|
|
118
|
+
h3::Header::new(b"woot", b"woot"),
|
|
119
|
+
h3::Header::new(b"hello", b"WorlD"),
|
|
120
|
+
h3::Header::new(b"foo", b"BaR"),
|
|
121
|
+
];
|
|
122
|
+
|
|
123
|
+
// Header.
|
|
124
|
+
let headers_in = vec![
|
|
125
|
+
h3::Header::new(b":StAtUs", b"200"),
|
|
126
|
+
h3::Header::new(b":PaTh", b"/HeLlO"),
|
|
127
|
+
h3::Header::new(b"WooT", b"woot"),
|
|
128
|
+
h3::Header::new(b"hello", b"WorlD"),
|
|
129
|
+
h3::Header::new(b"fOo", b"BaR"),
|
|
130
|
+
];
|
|
131
|
+
|
|
132
|
+
let mut enc = Encoder::new();
|
|
133
|
+
assert_eq!(enc.encode(&headers_in, &mut encoded), Ok(35));
|
|
134
|
+
|
|
135
|
+
let mut dec = Decoder::new();
|
|
136
|
+
let headers_out = dec.decode(&encoded, u64::MAX).unwrap();
|
|
137
|
+
|
|
138
|
+
assert_eq!(headers_expected, headers_out);
|
|
139
|
+
|
|
140
|
+
// HeaderRef.
|
|
141
|
+
let headers_in = vec![
|
|
142
|
+
h3::HeaderRef::new(b":StAtUs", b"200"),
|
|
143
|
+
h3::HeaderRef::new(b":PaTh", b"/HeLlO"),
|
|
144
|
+
h3::HeaderRef::new(b"WooT", b"woot"),
|
|
145
|
+
h3::HeaderRef::new(b"hello", b"WorlD"),
|
|
146
|
+
h3::HeaderRef::new(b"fOo", b"BaR"),
|
|
147
|
+
];
|
|
148
|
+
|
|
149
|
+
let mut enc = Encoder::new();
|
|
150
|
+
assert_eq!(enc.encode(&headers_in, &mut encoded), Ok(35));
|
|
151
|
+
|
|
152
|
+
let mut dec = Decoder::new();
|
|
153
|
+
let headers_out = dec.decode(&encoded, u64::MAX).unwrap();
|
|
154
|
+
|
|
155
|
+
assert_eq!(headers_expected, headers_out);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
#[test]
|
|
159
|
+
fn lower_ascii_range() {
|
|
160
|
+
let mut encoded = [0u8; 50];
|
|
161
|
+
let mut enc = Encoder::new();
|
|
162
|
+
|
|
163
|
+
// Indexed name with literal value
|
|
164
|
+
let headers1 = vec![h3::Header::new(b"location", b" ")];
|
|
165
|
+
assert_eq!(enc.encode(&headers1, &mut encoded), Ok(19));
|
|
166
|
+
|
|
167
|
+
// Literal name and value
|
|
168
|
+
let headers2 = vec![h3::Header::new(b"a", b"")];
|
|
169
|
+
assert_eq!(enc.encode(&headers2, &mut encoded), Ok(20));
|
|
170
|
+
|
|
171
|
+
let headers3 = vec![h3::Header::new(b" ", b"hello")];
|
|
172
|
+
assert_eq!(enc.encode(&headers3, &mut encoded), Ok(24));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
#[test]
|
|
176
|
+
fn extended_ascii_range() {
|
|
177
|
+
let mut encoded = [0u8; 50];
|
|
178
|
+
let mut enc = Encoder::new();
|
|
179
|
+
|
|
180
|
+
let name = b"location";
|
|
181
|
+
let value = "£££££££££££££££";
|
|
182
|
+
|
|
183
|
+
// Indexed name with literal value
|
|
184
|
+
let headers1 = vec![h3::Header::new(name, value.as_bytes())];
|
|
185
|
+
assert_eq!(enc.encode(&headers1, &mut encoded), Ok(34));
|
|
186
|
+
|
|
187
|
+
// Literal name and value
|
|
188
|
+
let value = "ððððððððððððððð";
|
|
189
|
+
let headers2 = vec![h3::Header::new(b"a", value.as_bytes())];
|
|
190
|
+
assert_eq!(enc.encode(&headers2, &mut encoded), Ok(35));
|
|
191
|
+
|
|
192
|
+
let headers3 = vec![h3::Header::new(value.as_bytes(), b"hello")];
|
|
193
|
+
assert_eq!(enc.encode(&headers3, &mut encoded), Ok(39));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
pub use decoder::Decoder;
|
|
198
|
+
pub use encoder::Encoder;
|
|
199
|
+
|
|
200
|
+
mod decoder;
|
|
201
|
+
mod encoder;
|
|
202
|
+
mod static_table;
|