angelnereira opened PR #13471 from angelnereira:serve-cli-headers to bytecodealliance:main:
Summary
Fixes #11925.
This adds
-H, --headertowasmtime serveso requests can be forwarded to the component with CLI-provided headers. This is useful when testing components that normally run behind a proxy or gateway that injects authentication, identity, routing, or other request metadata.Behavior:
--header 'name: value'replaces incoming request headers with the same name before the request is passed to the component.- The option can be provided more than once; repeated names produce multiple forwarded values in CLI order.
--header @path/to/headers.txtreads one header per non-empty line.Testing
cargo fmt --all -- --checkgit diff --checkcargo check -p wasmtime-clicargo test -p wasmtime-cli --test all p2_cli_serve_header_replaces_request_header
angelnereira requested pchickey for a review on PR #13471.
angelnereira requested wasmtime-core-reviewers for a review on PR #13471.
:memo: alexcrichton submitted PR review:
Thanks!
:speech_balloon: alexcrichton created PR review comment:
s/header/value/ in the error message perhaps?
:speech_balloon: alexcrichton created PR review comment:
Out of curiosity, how come this removes everything, then appends everything? I'd naively expect that remove-then-append for each key individually would work?
If it's for some specific behavior, could a test be added for that?
:speech_balloon: alexcrichton created PR review comment:
s/header/name/ in the error message perhaps?
:speech_balloon: alexcrichton created PR review comment:
Could you add a test for the file-reading behavior as well?
angelnereira commented on PR #13471:
Thanks for the review. I’ll update the two error messages, add coverage for @file header loading, and add a test/comment for the two-phase remove/append behavior to preserve repeated CLI-provided header values.
angelnereira updated PR #13471.
angelnereira updated PR #13471.
angelnereira commented on PR #13471:
Update pushed.
I kept the two-phase remove/append behavior intentionally: first remove all request-provided values for any CLI-specified header
name, then append all CLI-provided values in CLI order. This preserves repeated CLI-provided values for the same header name, which
would be lost if we removed and appended one entry at a time.I added coverage for that repeated-header case, added coverage for
--header=@file, and updated the error messages to distinguish
invalid header names from invalid header values.
:thumbs_up: alexcrichton submitted PR review.
alexcrichton added PR #13471 Add request headers to wasmtime serve to the merge queue.
:check: alexcrichton merged PR #13471.
alexcrichton removed PR #13471 Add request headers to wasmtime serve from the merge queue.
Last updated: Jun 01 2026 at 09:49 UTC