Ocelot
Ocelot copied to clipboard
More Flexible VersionPolicy
New 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?
Dear Ibnu, Why do you use v18 if the v19 is available?
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
I'm afraid Ocelot team doesn't support outdated versions and releases. We have no separate release branch for v18 because of the lack of resources. It is pretty hard to support even the current release version because of Tom's inactivity! So, we have an intention to support current release version (v19) only and you need to make all tests and design your solution using the latest Ocelot version which is v19.
Finally, What about upgrading to v19.0.2 ?
Pay attention that v18 (.NET 6) and v19 (.NET 7) target different .NET SDKs which can lead to different behavior of objects from System.Net
namespace, the behavior of HttpClient
and HttpRequest
!
hi, raman.
we're currently waiting for dotnet 8 to be released before we upgrade all services, including the gateway that uses ocelot.
So, we have an intention to support current release version (v19) only and you need to make all tests and design your solution using the latest Ocelot version which is v19.
that's also our plan. i failed to mention it in my first post. and i will write the pr as soon as i have my computer within my reach. please expect the pr around friday this week or next monday at the latest.
thanks for the attention and cooperation in advance.
Why did you close the issue?
With 99% probability the bug exists in .NET 7 release aka v19.0.2. We can backport the fix from current develop branch after delivery, to the some feature branch with old v18 commits. This is the question of feature management/delivery.
So, I believe we can still collaborate on your bug/issue for v18 to apply the final fix for both versions: v18 and v19. What do you think?
But sure, you need to understand, there will be no additional v18 release because I'm not owner to manage Ocelot efficiently. So, there will be no NuGet package v.18.0.1 with the fix, current .NET 6 release is v18.0.0 You will have to use the code from the bug fix branch and compile the Ocelot project manually targeting .NET 6...
Please, reopen the issue if you have an intention to contribute soon!
sorry, i closed this issue because i thought we reached an agreement that:
- this feature is welcome
- i will make a pr for this feature
- i will base the pr on
develop
branch. - there's no need to backport this feature to v18 branch.
personally, i don't mind using the latest version of Ocelot.
and re-opening this issue.
+ Accepted
A solution is ready in PR #1673
Implemented by PR #1673 Commit: https://github.com/ThreeMammals/Ocelot/commit/140f9b5ca07689943a46858f3394065094987634