Fix enum values in YARP environment configuration - #19403
Fix enum values in YARP environment configuration#19403air-hand (air-hand) wants to merge 4 commits into
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 19403Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 19403" |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR improves YARP environment-variable configuration generation by correctly flattening enum values and updates tests/docs to reflect the new behavior.
Changes:
- Add enum handling to
YarpEnvConfigGenerator.FlattenToEnvVarsso enum-typed properties serialize as strings. - Update the verified snapshot to include the new generated env var for
HttpVersionPolicy. - Add README documentation showing how to terminate TLS and proxy gRPC via h2c using
ForwarderRequestConfig.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/Aspire.Hosting.Yarp.Tests/Snapshots/YarpConfigGeneratorTests.GenerateEnvVariablesConfiguration.verified.env | Updates snapshot expectations to include the newly generated enum env var. |
| src/Aspire.Hosting.Yarp/YarpEnvConfigGenerator.cs | Adds enum flattening support so enums are emitted as scalar env var values. |
| src/Aspire.Hosting.Yarp/README.md | Documents the new/expected configuration pattern for TLS termination + h2c forwarding for gRPC. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/Aspire.Hosting.Yarp/YarpEnvConfigGenerator.cs:89
Enum.ToString()does not return null, so the null-coalescing fallback (?? "") is redundant here. Consider simplifying toenvironmentVariables.Add(prefix, obj.ToString());(orstring.Emptyif you want a consistent pattern elsewhere) to reduce noise and avoid implying null is expected.
else if (obj is Enum)
{
environmentVariables.Add(prefix, obj.ToString() ?? "");
}
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/Aspire.Hosting.Yarp/README.md:181
- This example may not work out-of-the-box on .NET without enabling HTTP/2 over cleartext (h2c) support (e.g., the
System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupportswitch). Consider adding a short note indicating that the gateway process must enable h2c support (and/or link to the relevant .NET documentation) so users don’t end up with HTTP/1.1 downgrade or gRPC failures.
### Terminate TLS and proxy h2c (for gRPC)
src/Aspire.Hosting.Yarp/YarpEnvConfigGenerator.cs:89
- Consider using pattern matching (
obj is Enum e) and formatting explicitly (e.g., general format) to make the intent clear and avoid relying onobject.ToString()for serialization semantics. This also makes it easier to adjust behavior later for flags enums (comma-separated values) if configuration binding ever needs stricter formatting.
else if (obj is Enum)
{
environmentVariables.Add(prefix, obj.ToString());
}
Description
WithForwarderRequestConfigcan setHttpVersionPolicy, but the container environment-variable generator drops enum values.This prevents YARP from receiving settings such as
RequestVersionExact, which are needed when an HTTPS-terminating proxy forwards gRPC traffic to an h2c backend.This change serializes enum values while flattening YARP configuration to environment variables.
In addition to
HttpVersionPolicy, it preserves explicitly configured route match modes and session-affinity cookie settings that were previously omitted.Urivalues are already recursively expanded; this change also emits theirHostNameTypeenum leaf.The README includes an h2c/gRPC example using
RequestVersionExact.The destination must use
http://, and its backend must accept HTTP/2 without TLS.User-facing usage
Validation:
Fixes # (issue)
Checklist
<remarks />and<code />elements on your triple slash comments?