Skip to content

Commit 511638f

Browse files
authored
Refactor wasi:http headers' host representation (bytecodealliance#12754)
* Refactor `wasi:http` headers' host representation This commit is a follow-on/extension of bytecodealliance#12748 and extends the changes made for WASIp2 headers in bytecodealliance#12652 to the WASIp3 implementation as well. This is done through a number of refactorings to make the WASIp2 and WASIp3 implementations more similar in terms of how they represent headers. Changes here are: * `FieldMap` now has its own dedicated module at the crate root instead of intermingling with other WASIp2 types. * `FieldMap` is now internally-`Arc`'d and is cheaply clonable. `FieldMap` itself now tracks whether it's mutable or immutable (WASI semantics) and doesn't need different wrappers in WASIp2 and WASIp3. * Creation of an immutable `FieldMap` can be done without needing a size limit. Flagging a `FieldMap` as mutable, however, requires a size limit. * `FieldMap::set` was added to be a bit more efficient w.r.t. clones. * `FieldMapError` is a new error type that covers all of the possible error modes of operating with a `FieldMap`. Conversions from this to WASIp{2,3} `header-error` types are now implemented as well. * WASIp2 now flags `header-error` as a trappable-error-type, allowing the use of `?` in implementing header functions (like WASIp3). * Much of WASIp2's header implementation was refactored with `?`, moving methods around, shuffling where headers are made vs `FieldMap`, some minor idioms, etc. * WASIp3 no longer uses `MaybeMutable` for headers and instead uses `FieldMap` directly. cc bytecodealliance#12674 * Clippy warnings
1 parent 9593a3a commit 511638f

19 files changed

Lines changed: 714 additions & 544 deletions

File tree

crates/test-programs/src/bin/p2_cli_http_headers.rs

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,71 @@
1-
fn main() {
2-
let fields = wasip2::http::types::Fields::new();
1+
use test_programs::p3::wasi as wasip3;
32

3+
fn main() {
44
match std::env::args().nth(1).as_deref() {
5-
Some("append") => {
5+
Some("p2-append") => {
6+
let fields = wasip2::http::types::Fields::new();
7+
for i in 0.. {
8+
if fields.append(&format!("a{i}"), b"a").is_err() {
9+
break;
10+
}
11+
}
12+
}
13+
Some("p2-append-empty") => {
14+
let fields = wasip2::http::types::Fields::new();
15+
for i in 0.. {
16+
if fields.append(&format!("a{i}"), b"").is_err() {
17+
break;
18+
}
19+
}
20+
}
21+
Some("p2-append-same") => {
22+
let fields = wasip2::http::types::Fields::new();
23+
loop {
24+
if fields.append("a", b"b").is_err() {
25+
break;
26+
}
27+
}
28+
}
29+
Some("p2-append-same-empty") => {
30+
let fields = wasip2::http::types::Fields::new();
31+
loop {
32+
if fields.append("a", b"").is_err() {
33+
break;
34+
}
35+
}
36+
}
37+
Some("p3-append") => {
38+
let fields = wasip3::http::types::Fields::new();
639
for i in 0.. {
740
if fields.append(&format!("a{i}"), b"a").is_err() {
841
break;
942
}
1043
}
1144
}
12-
Some("append-empty") => {
45+
Some("p3-append-empty") => {
46+
let fields = wasip3::http::types::Fields::new();
1347
for i in 0.. {
1448
if fields.append(&format!("a{i}"), b"").is_err() {
1549
break;
1650
}
1751
}
1852
}
19-
Some("append-same") => loop {
20-
if fields.append("a", b"b").is_err() {
21-
break;
53+
Some("p3-append-same") => {
54+
let fields = wasip3::http::types::Fields::new();
55+
loop {
56+
if fields.append("a", b"b").is_err() {
57+
break;
58+
}
2259
}
23-
},
24-
Some("append-same-empty") => loop {
25-
if fields.append("a", b"").is_err() {
26-
break;
60+
}
61+
Some("p3-append-same-empty") => {
62+
let fields = wasip3::http::types::Fields::new();
63+
loop {
64+
if fields.append("a", b"").is_err() {
65+
break;
66+
}
2767
}
28-
},
68+
}
2969
other => panic!("unknown test {other:?}"),
3070
}
3171

0 commit comments

Comments
 (0)