Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9e1c348
Use RFC-compliant HeaderValue type.
PiotrSikora Oct 22, 2024
0542a78
review: retain values from more forgiving hosts.
PiotrSikora Oct 27, 2024
3e9b789
Merge remote-tracking branch 'origin/main' into PiotrSikora/header-value
PiotrSikora Jun 4, 2025
9bf47e6
Merge remote-tracking branch 'origin/main' into PiotrSikora/header-value
PiotrSikora Jun 5, 2025
17b8b75
Merge branch 'main' into header-value
PiotrSikora Jun 5, 2025
21f1a97
review: add comment explaining the panic hook override in tests.
PiotrSikora Jun 5, 2025
ca5ea40
review: illegal -> invalid.
PiotrSikora Jun 26, 2025
34b6eb7
review: header-value -> strict-header-value.
PiotrSikora Jun 26, 2025
ddef068
Merge branch 'main' into header-value
PiotrSikora Jul 2, 2025
c9300d5
Merge remote-tracking branch 'origin/main' into PiotrSikora/header-value
PiotrSikora Jan 25, 2026
1155a99
review: update Bazel dependencies.
PiotrSikora Jan 25, 2026
a64ab45
review: fix memory leaks and add more alloc tests.
PiotrSikora Jan 25, 2026
c5ed28d
review: migrate from Cargo feature to _typed() suffix.
PiotrSikora Jan 25, 2026
be9ea36
review: use _bytes() variant as the common implementation.
PiotrSikora Jan 25, 2026
7c38daf
review: reorder functions (original -> _bytes() -> _typed()).
PiotrSikora Jan 25, 2026
b110464
review: style.
PiotrSikora Jan 25, 2026
a847b32
review: fix format in examples.
PiotrSikora Jan 25, 2026
b0e5d9b
review: convert remaining examples.
PiotrSikora Jan 25, 2026
25bcdf1
review: mark UTF-8 variants as deprecated.
PiotrSikora Jan 25, 2026
c1ddd0f
Merge branch 'main' into header-value
PiotrSikora Feb 11, 2026
3384e48
review: gate mocks on "mockalloc" feature.
PiotrSikora Feb 11, 2026
204ebd3
review: update bytes to v1.11.1.
PiotrSikora Feb 11, 2026
a4d1e4a
review: use _unchecked variant also for individual values.
PiotrSikora Feb 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ jobs:

- name: Format (rules_rust)
run: |
sed -i'' -E 's/^default = \[\]/default = \[\"strict-header-value\"\]/' Cargo.toml
bazelisk --noworkspace_rc run --noenable_bzlmod //bazel/cargo:crates_vendor
git checkout Cargo.toml
git diff --exit-code

msrv:
Expand Down Expand Up @@ -150,9 +152,18 @@ jobs:
- name: Clippy (wasm32-wasi)
run: cargo clippy --release --all-targets --target=wasm32-wasi

- name: Build (strict-header-value)
run: cargo build --release --all-targets --target=wasm32-wasi --features strict-header-value

- name: Clippy (strict-header-value)
run: cargo clippy --release --all-targets --target=wasm32-wasi --features strict-header-value

- name: Test
run: cargo test

- name: Test (strict-header-value)
run: cargo test --features strict-header-value

- name: Format (rustfmt)
run: cargo fmt -- --check

Expand Down Expand Up @@ -215,9 +226,18 @@ jobs:
- name: Clippy (wasm32-wasip1)
run: cargo clippy --release --all-targets --target=wasm32-wasip1

- name: Build (strict-header-value)
run: cargo build --release --all-targets --target=wasm32-wasip1 --features strict-header-value

- name: Clippy (strict-header-value)
run: cargo clippy --release --all-targets --target=wasm32-wasip1 --features strict-header-value

- name: Test
run: cargo test

- name: Test (strict-header-value)
run: cargo test --features strict-header-value

- name: Format (rustfmt)
run: cargo fmt -- --check

Expand Down Expand Up @@ -281,12 +301,24 @@ jobs:
- name: Clippy (wasm32-wasip1)
run: cargo clippy --release --all-targets --target=wasm32-wasip1

- name: Build (strict-header-value)
run: cargo build --release --all-targets --target=wasm32-wasip1 --features strict-header-value

- name: Clippy (strict-header-value)
run: cargo clippy --release --all-targets --target=wasm32-wasip1 --features strict-header-value

- name: Test
run: cargo test

- name: Test (strict-header-value)
run: cargo test --features strict-header-value

- name: Bench
run: cargo bench

- name: Bench (strict-header-value)
run: cargo bench --features strict-header-value

- name: Format (rustfmt)
run: cargo fmt -- --check

Expand Down
30 changes: 30 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ rust_library(
],
)

rust_library(
name = "proxy_wasm_strict_header_value",
srcs = glob(["src/*.rs"]),
crate_features = ["strict-header-value"],
crate_name = "proxy_wasm",
edition = "2018",
visibility = ["//visibility:public"],
deps = [
":proxy_wasm_build_script",
"//bazel/cargo/remote:bytes",
"//bazel/cargo/remote:hashbrown",
"//bazel/cargo/remote:http",
"//bazel/cargo/remote:log",
],
)

rust_binary(
name = "http_auth_random",
srcs = ["examples/http_auth_random/src/lib.rs"],
Expand All @@ -52,3 +68,17 @@ rust_binary(
"//bazel/cargo/remote:log",
],
)

rust_binary(
name = "grpc_auth_random",
srcs = ["examples/grpc_auth_random/src/lib.rs"],
crate_type = "cdylib",
edition = "2018",
out_binary = True,
rustc_flags = ["-Cstrip=debuginfo"],
visibility = ["//visibility:private"],
deps = [
":proxy_wasm_strict_header_value",
"//bazel/cargo/remote:log",
],
)
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ edition = "2018"
build = "build.rs"

[dependencies]
bytes = { version = "1", optional = true }
hashbrown = "0.15"
http = { version = "1", optional = true }
log = "0.4"

[features]
default = []
strict-header-value = ["dep:bytes", "dep:http"]

[profile.release]
lto = true
opt-level = 3
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
[license-badge]: https://img.shields.io/github/license/proxy-wasm/proxy-wasm-rust-sdk
[license-link]: https://github.com/proxy-wasm/proxy-wasm-rust-sdk/blob/main/LICENSE

## Crate features

This crate supports the following optional features:

- `strict-header-value` - uses RFC-compliant `HeaderValue` instead of UTF-8 `String` for HTTP header and trailer values.
This will become the default in future releases.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this PR doesn't introduce any changes or restrictions on header names in the SDK, since all valid HTTP field names are also valid UTF-8 strings, and proxies are very strict about this, so we never panic deserializing header names.

Having said that, I'm tempted to use HeaderName type while we're here, and turn this into a full typed variant.

Unfortunately, because we're passing HTTP/2 pseudo-headers (:authority, :status, etc.) in the header map, those names are non-compliant with RFC HTTP field names, so we'd need to either:

  1. create wrapper around http::HeaderName type,
  2. create our own more forgiving type,
  3. return a pair of maps, one with pseudo-headers and one with HTTP headers.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unfortunate that http::HeaderName can't accomodate pseudo-headers, since that's a very common case. What does other Rust code do for handling H2 pseudo-headers, just use strings?

If there isn't any good external precedent, maybe (1), in the form of an enum type that can either be an http::HeaderName or a pseudo-header? Or would http::HeaderName plus a pseudoheader bool be sufficient to represent all cases?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unfortunate that http::HeaderName can't accomodate pseudo-headers, since that's a very common case. What does other Rust code do for handling H2 pseudo-headers, just use strings?

Pseudo-headers are a wire-format detail, and they are not intermixed with HTTP headers in any library or language that I'm aware of (other than Envoy), so that's not an issue that other people run into.

If there isn't any good external precedent, maybe (1), in the form of an enum type that can either be an http::HeaderName or a pseudo-header? Or would http::HeaderName plus a pseudoheader bool be sufficient to represent all cases?

http::HeaderName cannot contain : character, so a pseudoheader flag wouldn't work.

My other concern was that even if we "patch" http::HeaderName somehow, we still wouldn't be able to use http::HeaderMap that uses original http::HeaderName as long as pseudo-headers are intermixed with the regular HTTP headers.

I think we should separate them, at the very least at the SDK level, otherwise we're just propagating this Envoy-ism and making it hard-to-impossible to interoperate with the generic HTTP libraries available in various languages.

I'm sure this isn't helpful in Go SDK either.


## Examples

- [Hello World](./examples/hello_world/)
Expand Down
31 changes: 31 additions & 0 deletions bazel/cargo/Cargo.Bazel.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@ version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"

[[package]]
name = "bytes"
version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a"

[[package]]
name = "equivalent"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"

[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"

[[package]]
name = "foldhash"
version = "0.1.5"
Expand All @@ -31,6 +43,23 @@ dependencies = [
"foldhash",
]

[[package]]
name = "http"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565"
dependencies = [
"bytes",
"fnv",
"itoa",
]

[[package]]
name = "itoa"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"

[[package]]
name = "log"
version = "0.4.27"
Expand All @@ -41,6 +70,8 @@ checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
name = "proxy-wasm"
version = "0.2.4-dev"
dependencies = [
"bytes",
"hashbrown",
"http",
"log",
]
24 changes: 24 additions & 0 deletions bazel/cargo/remote/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ filegroup(
)

# Workspace Member Dependencies
alias(
name = "bytes-1.10.1",
actual = "@crates_vendor__bytes-1.10.1//:bytes",
tags = ["manual"],
)

alias(
name = "bytes",
actual = "@crates_vendor__bytes-1.10.1//:bytes",
tags = ["manual"],
)

alias(
name = "hashbrown-0.15.3",
actual = "@crates_vendor__hashbrown-0.15.3//:hashbrown",
Expand All @@ -43,6 +55,18 @@ alias(
tags = ["manual"],
)

alias(
name = "http-1.3.1",
actual = "@crates_vendor__http-1.3.1//:http",
tags = ["manual"],
)

alias(
name = "http",
actual = "@crates_vendor__http-1.3.1//:http",
tags = ["manual"],
)

alias(
name = "log-0.4.27",
actual = "@crates_vendor__log-0.4.27//:log",
Expand Down
96 changes: 96 additions & 0 deletions bazel/cargo/remote/BUILD.bytes-1.10.1.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
###############################################################################
# @generated
# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To
# regenerate this file, run the following:
#
# bazel run @//bazel/cargo:crates_vendor
###############################################################################

load("@rules_rust//cargo:defs.bzl", "cargo_toml_env_vars")
load("@rules_rust//rust:defs.bzl", "rust_library")

package(default_visibility = ["//visibility:public"])

cargo_toml_env_vars(
name = "cargo_toml_env_vars",
src = "Cargo.toml",
)

rust_library(
name = "bytes",
srcs = glob(
include = ["**/*.rs"],
allow_empty = True,
),
compile_data = glob(
include = ["**"],
allow_empty = True,
exclude = [
"**/* *",
".tmp_git_root/**/*",
"BUILD",
"BUILD.bazel",
"WORKSPACE",
"WORKSPACE.bazel",
],
),
crate_features = [
"default",
"std",
],
crate_root = "src/lib.rs",
edition = "2018",
rustc_env_files = [
":cargo_toml_env_vars",
],
rustc_flags = [
"--cap-lints=allow",
],
tags = [
"cargo-bazel",
"crate-name=bytes",
"manual",
"noclippy",
"norustfmt",
],
target_compatible_with = select({
"@rules_rust//rust/platform:aarch64-apple-darwin": [],
"@rules_rust//rust/platform:aarch64-apple-ios": [],
"@rules_rust//rust/platform:aarch64-apple-ios-sim": [],
"@rules_rust//rust/platform:aarch64-linux-android": [],
"@rules_rust//rust/platform:aarch64-pc-windows-msvc": [],
"@rules_rust//rust/platform:aarch64-unknown-fuchsia": [],
"@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [],
"@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [],
"@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [],
"@rules_rust//rust/platform:aarch64-unknown-uefi": [],
"@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [],
"@rules_rust//rust/platform:armv7-linux-androideabi": [],
"@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [],
"@rules_rust//rust/platform:i686-apple-darwin": [],
"@rules_rust//rust/platform:i686-linux-android": [],
"@rules_rust//rust/platform:i686-pc-windows-msvc": [],
"@rules_rust//rust/platform:i686-unknown-freebsd": [],
"@rules_rust//rust/platform:i686-unknown-linux-gnu": [],
"@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [],
"@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [],
"@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [],
"@rules_rust//rust/platform:s390x-unknown-linux-gnu": [],
"@rules_rust//rust/platform:thumbv7em-none-eabi": [],
"@rules_rust//rust/platform:thumbv8m.main-none-eabi": [],
"@rules_rust//rust/platform:wasm32-unknown-unknown": [],
"@rules_rust//rust/platform:wasm32-wasip1": [],
"@rules_rust//rust/platform:x86_64-apple-darwin": [],
"@rules_rust//rust/platform:x86_64-apple-ios": [],
"@rules_rust//rust/platform:x86_64-linux-android": [],
"@rules_rust//rust/platform:x86_64-pc-windows-msvc": [],
"@rules_rust//rust/platform:x86_64-unknown-freebsd": [],
"@rules_rust//rust/platform:x86_64-unknown-fuchsia": [],
"@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [],
"@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [],
"@rules_rust//rust/platform:x86_64-unknown-none": [],
"@rules_rust//rust/platform:x86_64-unknown-uefi": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
version = "1.10.1",
)
Loading
Loading