More Flexible VersionPolicy
See original GitHub issueNew Feature
Configurable HttpRequestMessage.VersionPolicy
.
Motivation for New Feature
The following setup:
- an MVC ASP.NET Core as frontend.
- Ocelot gateway
- some microservices
All components above configured to use Kestrel with the following snippet:
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureKestrel(opts =>
{
opts.ConfigureEndpointDefaults(lopts =>
{
lopts.Protocols = HttpProtocols.Http2;
});
});
All components above should only talk to each other using HTTP/2 and no TLS (plain HTTP).
User Scenario
With plain Ocelot 18.0.0, I couldn’t make them talk to each other with plain HTTP from frontend to the service. The services will print out error messages like the following:
HTTP/2 connection error (PROTOCOL_ERROR): Invalid HTTP/2 connection preface
Solution
Found out that I need to make sure that HttpRequestMessage
has its VersionPolicy
to be set RequestVersionOrHigher
.
Changes I made
- namespace:
Ocelot.Request.Mapper
class:RequestMapper
method:Task<Response<HttpRequestMessage>> Map(HttpRequest request, DownstreamRoute downstreamRoute)
changes:- added
VersionPolicy = HttpVersionPolicy.RequestVersionOrHigher,
inHttpRequestMessage
instantiation.
- added
- namespace:
Ocelot.Requester
class:HttpClientBuilder
method:IHttpClient Create(DownstreamRoute downstreamRoute)
changes:- added
DefaultRequestVersion = downstreamRoute.DownstreamHttpVersion,
andDefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrHigher,
inHttpClient
instantiation.
- added
Then all those components above can talk to each other in HTTP/2.
And I think DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrHigher
could be DefaultVersionPolicy downstreamRoute.DownstreamHttpVersionPolicy
.
And I am willing to make a PR if you fine folks think this kind of changes is welcome.
Specifications
- Version: 18.0.0
- Platform: ASP.NET Core 6.0
- Subsystem: ASP.NET 6.0 Docker image. Should be Debian, yes?
Issue Analytics
- State:
- Created 3 months ago
- Comments:5 (3 by maintainers)
sorry, i closed this issue because i thought we reached an agreement that:
develop
branch.personally, i don’t mind using the latest version of Ocelot.
and re-opening this issue.
A solution is ready in PR #1673