Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 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
3806d92
Merge remote-tracking branch 'origin/main' into PiotrSikora/header-value
PiotrSikora Jul 3, 2026
338478e
review: update version in deprecation notice to v0.3.0.
PiotrSikora Jul 3, 2026
a4914a0
review: use correct MapType in get_http_call_response_header_typed.
PiotrSikora Jul 3, 2026
7aa0e9e
review: update bytes and http crates.
PiotrSikora Jul 3, 2026
eb4d97f
review: document behavior of the unchecked variant in debug builds.
PiotrSikora Jul 3, 2026
aaeda2e
review: fix clippy warning.
PiotrSikora Jul 4, 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
20 changes: 20 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ jobs:

- name: Format (rules_rust)
run: |
sed -i'' -E 's/^default = \[\]/default = \[\"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 @@ -148,6 +150,12 @@ jobs:
- name: Clippy (wasm32-wasi)
run: cargo clippy --release --all-targets --target=wasm32-wasi

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

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

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

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

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

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

Comment thread
PiotrSikora marked this conversation as resolved.
- name: Format (rustfmt)
run: cargo fmt -- --check

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

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

- name: Clippy (header-value)
run: cargo clippy --release --all-targets --target=wasm32-wasip1 --features 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_header_value",
srcs = glob(["src/*.rs"]),
crate_features = ["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_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 = []
header-value = ["dep:bytes", "dep:http"]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This feature could be renamed to valid-header, strict-header or rfc-header to make this reusable in case we want to add restrictions on header name in the future.

Alternatively, we could drop this as a feature and instead add those functions as variants with _typed() suffix.

Thoughts?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

_typed() suffix would fit alongside the existing _bytes() suffix, so doesn't seem too bad to me.

No objection to keeping it as a feature, though, assuming we find a solution to the HTTP/2 pseudo-headers problem. If you keep it a feature, strict-header or rfc-header SGTM.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

_typed() suffix would fit alongside the existing _bytes() suffix, so doesn't seem too bad to me.

Since the original version without suffix is fundamentally broken for the HTTP use case, I think we should drop it sooner rather than later, so I'll stick to the version from the existing revision of this PR and leave it without suffix behind a feature flag.

No objection to keeping it as a feature, though, assuming we find a solution to the HTTP/2 pseudo-headers problem.

Pseudo-header issue is orthogonal to this, since it only affects HTTP header names, and not values (this PR).

If you keep it a feature, strict-header or rfc-header SGTM.

My original thinking was that we need to have a flag for both: values only (this PR) and for both, so that we could add support for http::HeaderName and http::HeaderMap in a separate PR without making it a breaking change.

Having said that, I suspect that adding support for the latter is going to require splitting pseudo-headers and regular HTTP headers into separate maps, so it might be a much bigger change that'd be done as part of a bigger rewrite and not something simply hidden behind a feature flag.

Using http::HeaderValue is much more important, since the UTF-8 issue is causing panics and is pretty much broken.

Using http::HeaderName and http::HeaderMap only gives us better integration with existing Rust's HTTP ecosystem, but it doesn't really fix any issues, so it's a nice-to-have.

So strict-header-value (this PR) and strict-header (once we have support for both)?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

So strict-header-value (this PR) and strict-header (once we have support for both)?

SGTM

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I had a change of heart and I converted this PR to functions with a _typed() suffix instead of the strict-header-value cargo feature.

I believe that this will result in a better migration process for the plugin authors, because:

  • both the UTF-8 and HeaderValue variants will be available at the same time,
  • UTF-8 version can be marked as #[deprecated], which will send a clear signal to anybody upgrading to use HeaderValue variant, without breaking build for "unmaintained" plugins.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've pushed the #[deprecated] changes here as well, to make it easier to see the complete picture, but I can easily spit it into a separate PR if needed. Let me know.


[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:

- `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
Copy Markdown
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.

Copy link
Copy Markdown

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
Copy Markdown
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.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f"

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

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

[[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.3"
Expand All @@ -31,6 +43,23 @@ dependencies = [
"foldhash",
]

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

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

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

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

alias(
name = "hashbrown",
actual = "@crates_vendor__hashbrown-0.15.0//:hashbrown",
tags = ["manual"],
)

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

alias(
name = "log",
actual = "@crates_vendor__log-0.4.22//:log",
Expand Down
85 changes: 85 additions & 0 deletions bazel/cargo/remote/BUILD.bytes-1.8.0.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
###############################################################################
# @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//rust:defs.bzl", "rust_library")

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

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_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-fuchsia": [],
"@rules_rust//rust/platform:aarch64-linux-android": [],
"@rules_rust//rust/platform:aarch64-pc-windows-msvc": [],
"@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: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-wasi": [],
"@rules_rust//rust/platform:x86_64-apple-darwin": [],
"@rules_rust//rust/platform:x86_64-apple-ios": [],
"@rules_rust//rust/platform:x86_64-fuchsia": [],
"@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-linux-gnu": [],
"@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [],
"@rules_rust//rust/platform:x86_64-unknown-none": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
version = "1.8.0",
)
85 changes: 85 additions & 0 deletions bazel/cargo/remote/BUILD.fnv-1.0.7.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
###############################################################################
# @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//rust:defs.bzl", "rust_library")

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

rust_library(
name = "fnv",
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 = "lib.rs",
edition = "2015",
rustc_flags = [
"--cap-lints=allow",
],
tags = [
"cargo-bazel",
"crate-name=fnv",
"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-fuchsia": [],
"@rules_rust//rust/platform:aarch64-linux-android": [],
"@rules_rust//rust/platform:aarch64-pc-windows-msvc": [],
"@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: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-wasi": [],
"@rules_rust//rust/platform:x86_64-apple-darwin": [],
"@rules_rust//rust/platform:x86_64-apple-ios": [],
"@rules_rust//rust/platform:x86_64-fuchsia": [],
"@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-linux-gnu": [],
"@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [],
"@rules_rust//rust/platform:x86_64-unknown-none": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
version = "1.0.7",
)
Loading