Skip to content

YARP direct forwarding: document service discovery with a custom HttpMessageInvoker - #38229

Open
assemkhashaba404 wants to merge 1 commit into
dotnet:mainfrom
assemkhashaba404:yarp-service-discovery-custom-invoker
Open

assemkhashaba404 wants to merge 1 commit into
dotnet:mainfrom
assemkhashaba404:yarp-service-discovery-custom-invoker

Conversation

@assemkhashaba404

@assemkhashaba404 assemkhashaba404 commented Nov 27, 2026 •

Copy link
Copy Markdown

Contributes to dotnet/yarp#2838

What

Adds a short subsection, "Service discovery and a custom HTTP client", to the YARP direct forwarding article.

Why

dotnet/yarp#2838 reports that MapForwarder resolves Aspire/service-discovery names such as https://api by default, but fails with "No such host" once a custom HttpMessageInvoker is passed in. The article doesn't mention this.

The cause: AddHttpForwarderWithServiceDiscovery registers a service-discovery-aware IForwarderHttpClientFactory, and a custom HttpMessageInvoker bypasses it. The new text says that, and shows how to keep service discovery by wrapping the inner handler with IServiceDiscoveryHttpMessageHandlerFactory.CreateHandler(...).

How it was checked

I reproduced all three cases with a small local app (.NET 8 SDK, Yarp.ReverseProxy 2.3.0, Microsoft.Extensions.ServiceDiscovery and Microsoft.Extensions.ServiceDiscovery.Yarp 11.0.1, "api" resolved from configuration):

  • default MapForwarder with AddHttpForwarderWithServiceDiscovery: request succeeds
  • custom HttpMessageInvoker(new SocketsHttpHandler{...}): 502, "Name or service not known (api:80)"
  • custom invoker wrapped with IServiceDiscoveryHttpMessageHandlerFactory.CreateHandler(...): request succeeds

The repro used http://api and AllowAutoRedirect = true. The sample in the article uses https://api and AllowAutoRedirect = false, so it was not run exactly as written, though the mechanism is the same. I did not run the docs build.

AI disclosure

This change was written by an AI assistant (Instinct) working for the PR author, and verified with the local repro above. The article already carries ai-usage: ai-assisted. I did not change ms.date; happy to update it if reviewers want.


Internal previews

File Preview link
aspnetcore/fundamentals/servers/yarp/direct-forwarding.md Learn preview
aspnetcore/security/authorization/custom-authorization-policies-with-iauthorizationrequirementdata.md Learn preview

Build report

@assemkhashaba404

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

@guardrex guardrex self-assigned this Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants