-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#360 Routing based on request header #1312
#360 Routing based on request header #1312
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good with one little comment ;)
Thanks for this PR! This is something super useful :) Do we know if this is going to be released soon? Best, |
I agree this is super useful and should be released |
Vote up! Any word on when this will be released? |
Hello. Just wanted to check in to see if there is any progress to release this? |
Hi @jlukawska, Any news ? |
Hi, please accept it. We are really needing this feature and this is opened since 2020 |
Unfortunately, I don't have rights to merge it. It seems that the Ocelot project has been abandoned by its owner :( |
@felipepiresdejesus commented on Apr 13, 2023:
Don't worry, Felipe! 😊 Will you resolve all merge conflicts? 😉 |
Well... @jlukawska Before resolving merge conflicts for this PR, could we work on develop branch in your fork, please? Step 1To fix that you need to remove current top-commit which is merge commit (it has 2 parents). Use this command: git checkout develop
git reset --hard HEAD~1 Reset command will report: After that, try to Sync fork please? Step 2Because you have other merge commits in develop branch which don't belong to head repository, I expect Sync Fork will fail because of some reason. In this case it is better just to remove develop branch, and provide new Sync Fork to pull develop branch entirely. Step 3If step 2 failed (no the same top commit in develop), just delete develop branch using GitHub UI and make git remote add upstream https://github.com/ThreeMammals/Ocelot.git // add original repo as upstream remote
git fetch upstream // pull changes from original repo
git checkout -b develop upstream/develop // pull down develop branch locally
git push -u origin develop // push develop branch to fork Don't forget to make develop branch as default one. Let me know upgrading results for develop branch, please! |
f5f437a
to
8adb2e8
Compare
The feature branch has been rebased onto ThreeMammals:develop! ✔️ @jlukawska |
@BrettJG As the issue #360 author, @netren20000 @iderbyshev @pliolis @lalocarbone @Phiph @mrclayman @jrsanbornjr @sachinjagdale @SebastianMajewski @falcopr @brettwinters @RickJNash @PraveenValavan |
@Thanos06660 @fadil-khodabuccus-cko @CorporateActionMan @stodolos @madebykrol @akanmf @felipepiresdejesus |
Please use language version 12.0 or greater.
a9ab2a3
to
6aeef96
Compare
src/Ocelot/Configuration/Creator/IUpstreamHeaderTemplatePatternCreator.cs
Outdated
Show resolved
Hide resolved
src/Ocelot/Configuration/Creator/UpstreamHeaderTemplatePatternCreator.cs
Show resolved
Hide resolved
src/Ocelot/Configuration/Creator/UpstreamHeaderTemplatePatternCreator.cs
Outdated
Show resolved
Hide resolved
src/Ocelot/Configuration/Validator/FileConfigurationFluentValidator.cs
Outdated
Show resolved
Hide resolved
src/Ocelot/Configuration/Validator/FileConfigurationFluentValidator.cs
Outdated
Show resolved
Hide resolved
src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteCreator.cs
Outdated
Show resolved
Hide resolved
src/Ocelot/DownstreamRouteFinder/Finder/DownstreamRouteFinder.cs
Outdated
Show resolved
Hide resolved
src/Ocelot/DownstreamRouteFinder/HeaderMatcher/IHeaderPlaceholderNameAndValueFinder.cs
Outdated
Show resolved
Hide resolved
Check grammar and style
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Development Complete❕
Awaiting Final Code Reviews❗
@ggnaegi Could you review please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ggnaegi Take a look at the new static class in the Ocelot.DependencyInjection
namespace!
// Features | ||
Services.AddHeaderRouting(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ggnaegi So, this adds the feature. Additionally, you've restructured the code and introduced a new MessageInvokerPool feature at line 120: Services.AddOcelotMessageInvokerPool();
.
I'm interested in expanding on this concept. It would be beneficial to have a feature-based design for Ocelot in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ready for delivery ✅
- Code review ✔️✔️
- Team approvals ✔️✔️✔️
- Unit testing ✔️✔️✔️ →
UpstreamHeaderTemplatePatternCreatorTests
HeaderPlaceholderNameAndValueFinderTests
HeadersToHeaderTemplatesMatcherTests
- extra
FileConfigurationFluentValidatorTests
,DownstreamRouteFinderTests
- Acceptance testing ✔️ →
RoutingBasedOnHeadersTests
- Feature docs ✔️ → routing.rst
@jlukawska Dear Jolanta, Congrats on this significant milestone! 🥳Good job! Your dedication and hard work are truly appreciated. I hope to see you return to our project soon! 😇 P.S.The feature will be officially released once all PRs associated with the Annual 2023 milestone are successfully closed.
|
* routing based on headers (all specified headers must match) * routing based on headers for aggregated routes * unit tests and small modifications * find placeholders in header templates * match upstream headers to header templates * find placeholders name and values, fix regex for finding placeholders values * fix unit tests * change header placeholder pattern * unit tests * unit tests * unit tests * unit tests * extend validation with checking upstreamheadertemplates, acceptance tests for cases from the issue * update docs and minor changes * SA1649 File name should match first type name * Fix compilation errors by code review after resolving conflicts * Fix warnings * File-scoped namespaces * File-scoped namespace * Target-typed 'new' expressions (C# 9). https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/target-typed-new * IDE1006 Naming rule violation: These words must begin with upper case characters: should_* * Target-typed 'new' expressions (C# 9). https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/target-typed-new * Fix build errors * DownstreamRouteBuilder * AggregatesCreator * IUpstreamHeaderTemplatePatternCreator, RoutesCreator * UpstreamHeaderTemplatePatternCreator * FileAggregateRoute * FileAggregateRoute * FileRoute * Route, IRoute * FileConfigurationFluentValidator * OcelotBuilder * DownstreamRouteCreator * DownstreamRouteFinder * HeaderMatcher * DownstreamRouteFinderMiddleware * UpstreamHeaderTemplate * Routing folder * RoutingBasedOnHeadersTests * Refactor acceptance tests * AAA pattern in unit tests * CS8936: Feature 'collection expressions' is not available in C# 10.0. Please use language version 12.0 or greater. * Code review by @RaynaldM * Convert facts to one `Theory` * AAA pattern * Add traits * Update routing.rst Check grammar and style * Update docs --------- Co-authored-by: raman-m <[email protected]>
* routing based on headers (all specified headers must match) * routing based on headers for aggregated routes * unit tests and small modifications * find placeholders in header templates * match upstream headers to header templates * find placeholders name and values, fix regex for finding placeholders values * fix unit tests * change header placeholder pattern * unit tests * unit tests * unit tests * unit tests * extend validation with checking upstreamheadertemplates, acceptance tests for cases from the issue * update docs and minor changes * SA1649 File name should match first type name * Fix compilation errors by code review after resolving conflicts * Fix warnings * File-scoped namespaces * File-scoped namespace * Target-typed 'new' expressions (C# 9). https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/target-typed-new * IDE1006 Naming rule violation: These words must begin with upper case characters: should_* * Target-typed 'new' expressions (C# 9). https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/target-typed-new * Fix build errors * DownstreamRouteBuilder * AggregatesCreator * IUpstreamHeaderTemplatePatternCreator, RoutesCreator * UpstreamHeaderTemplatePatternCreator * FileAggregateRoute * FileAggregateRoute * FileRoute * Route, IRoute * FileConfigurationFluentValidator * OcelotBuilder * DownstreamRouteCreator * DownstreamRouteFinder * HeaderMatcher * DownstreamRouteFinderMiddleware * UpstreamHeaderTemplate * Routing folder * RoutingBasedOnHeadersTests * Refactor acceptance tests * AAA pattern in unit tests * CS8936: Feature 'collection expressions' is not available in C# 10.0. Please use language version 12.0 or greater. * Code review by @RaynaldM * Convert facts to one `Theory` * AAA pattern * Add traits * Update routing.rst Check grammar and style * Update docs --------- Co-authored-by: raman-m <[email protected]>
Feature commit in develop → 6cef42e |
Closes #360
Proposed Changes
Additionally to routing by
UpstreamPathTemplate
, you can defineUpstreamHeaderTemplates
. Then to match a route, all the headers from this section must exist in the request headers.The example:
In this case the route will be matched only if a request has both headers set to the configured values.
You can use placeholders in your
UpstreamHeaderTemplates
in the following way:In this case the whole value for the request header version will be placed into the
DownstreamPathTemplate
. If you need, you can specify more complex upstream header template with placeholders like e.g.version-{header:version}_country-{header:country}
.Placeholders do not have to exist in
DownstreamPathTemplate
. This case may be used to require specific header no matter what the value it contains.UpstreamHeaderTemplates
section can be used also for Aggregates.