-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Routing based on Request Header #360
Comments
@BrettJG thanks for your interest in the project. Ocelot doesn’t support this at the moment but we could add it as a feature. I’m working on another issue at the moment but when I have finished I’ll take a look at this. |
yes, i need it too! |
@netren20000 cool thanks for letting me know! I will try and do this ASAP! I am very busy at the moment just answering questions and fixing bugs! Hopefully once all the bugs are sorted out I will do this feature! |
Hi @TomPallister . I'm currently trying to use it in a multi tenant solution which is hosted in Service Fabric.
Though it works like a charm, looks like a hack. |
@iderbyshev nice! doesnt feel like to bad a hack! Ocelot can't do everything :) I will bear this in mind and lets see if we can do something to make this better in the future! |
Expected Behavior / New Feature Actual Behavior / Motivation for New Feature I would like to configure Ocelot in a such way, so that v1 will be routed to Api 1, v2 to Api 2 an so on. I can think about following problem with this approach: Current implementation |
yes, i need it too in a multi tenant scenario. |
Excellent and amazing work Tom. Need it too for a multi tenant scenario as well !!!! |
Yeah header based routing would also be useful for me :) - for a multi tennant scenario |
Hi all, "UpstreamHeaderRoutingOptions": {
"Headers": {
"Header1": [ "AllowedValue1", "AllowedValue2" ],
"Header2": [ "AllowedValue1", "AllowedValue2" ]
},
"CombinationMode": "<one of Any/All>"
} Any value from the set of values associated with a single header is currently sufficient for the header to match. Thanks! |
I'm looking for this functionality also. Described spot on earlier " v1 will be routed to Api 1, v2 to Api 2". Any recent news on how this effort is going?? Thanks |
Hi @jrsanbornjr , I created a pull request #964 a few months ago for the guys to have a look at what I had done. I haven't received any feedback so I do not know if they had a look at it in the meantime. However, I have gotten to the point where I would prefer being able to route based on claim values so I will likely look into that. Therefore, it might be preferable if my pull request was not actually merged before I get this done. I am also strongly considering adding support for placeholders as per one of the suggestions above, so that one could specify something like this in the configuration "UpstreamRoutingHeaders": {
"Headers": {
"MyHeader": [ "HeaderValue" ]
}
},
"DownstreamPathTemplate" : "https://service/{header:MyHeader}/path" which seems pretty nifty to me. Similarly, claims might have something like |
I am also waiting for this functionality to support my legacy v1 api and v2 microservice. Will need to have unique gateway route which only be differentiated on header. |
Claims could also be good. I was looking to differentiate V1 / V2 for a
service by a header value, but I think claims could do the same thing. my
V1 service requires no authentication or authorization, but I'd like to add
a bearer token requirement to V2 to restrict / log client activity.
…On Mon, Sep 23, 2019 at 10:04 AM mrclayman ***@***.***> wrote:
Hi @jrsanbornjr <https://github.com/jrsanbornjr> , I created a pull
request #964 <#964> a few
months ago for the guys to have a look at what I had done. I haven't
received any feedback so I do not know if they had a look at it in the
meantime.
However, I have gotten to the point where I would prefer being able to
route based on claim values so I will likely look into that. Therefore, it
might be preferable if my pull request was not actually merged before I get
this done.
I am also strongly considering adding support for placeholders as per one
of the suggestions above, so that one could specify something like this in
the configuration
"UpstreamRoutingHeaders": {
"Headers": {
"MyHeader": [ "HeaderValue" ]
}
},
"DownstreamPathTemplate" : "https://service/{header:MyHeader}/path"
which seems pretty nifty to me. Similarly, claims might have something
like http://service/{claim:ClaimName}/path. I have not got around to this
yet, though. 🙁
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#360?email_source=notifications&email_token=ABW723OQHNMIOKDTSEYIG53QLDLGTA5CNFSM4FACFRPKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7LFKCA#issuecomment-534140168>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABW723NQ64HNO4TK5XVP5QLQLDLGTANCNFSM4FACFRPA>
.
|
Thanks @jrsanbornjr for suggestion. Seems good option if routes differentiated on claims as well. Either header or claims feature support needed to differentiate v1 or v2 routes . Will also check on how to extend ocelot in my code for forwarding requesr to correct downstream routes based on header/claims. Please suggest if you have done something like that. |
@sachinjagdale, are you going to try to implement this? I think I will finally be able to find the time over the next several days to look into adding claim-based routing and placeholder support for claims and headers, so that we don't end up messing with the same code. |
@mrclayman great job. Are you planning add header value matching? I need it for my scenario. |
Apologies! I've been sidetracked lately. I will have a look at this today.
…On Mon, Sep 23, 2019 at 10:04 AM mrclayman ***@***.***> wrote:
Hi @jrsanbornjr <https://github.com/jrsanbornjr> , I created a pull
request #964 <#964> a few
months ago for the guys to have a look at what I had done. I haven't
received any feedback so I do not know if they had a look at it in the
meantime.
However, I have gotten to the point where I would prefer being able to
route based on claim values so I will likely look into that. Therefore, it
might be preferable if my pull request was not actually merged before I get
this done.
I am also strongly considering adding support for placeholders as per one
of the suggestions above, so that one could specify something like this in
the configuration
"UpstreamRoutingHeaders": {
"Headers": {
"MyHeader": [ "HeaderValue" ]
}
},
"DownstreamPathTemplate" : "https://service/{header:MyHeader}/path"
which seems pretty nifty to me. Similarly, claims might have something
like http://service/{claim:ClaimName}/path. I have not got around to this
yet, though. 🙁
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#360?email_source=notifications&email_token=ABW723OQHNMIOKDTSEYIG53QLDLGTA5CNFSM4FACFRPKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7LFKCA#issuecomment-534140168>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABW723NQ64HNO4TK5XVP5QLQLDLGTANCNFSM4FACFRPA>
.
|
I also apologize for the delay, other more important tasks got in the way. I managed to clear my backlog a little, so hopefully I will finally have more time now. @SebastianMajewski it was not planned intially, but I will give some time to research how difficult it would be to implement. 🙂 |
Is there some update about this feature? |
I also think I need this feature for my multi-tenant application. I'm using different subdomains for my clients and basically I want to use the "origin" header to switch authentication schemes route uses Finbuckle to configure via http call to a tenant service {
"AuthenticationOptions": {
"AuthenticationProviderKey": "TenantAuthentication",
"AllowedScopes": []
}
}, and this route for admins {
"UpstreamRoutingHeaders": {
"Headers": {
"Origin": [ "admin.xxx.com" ]
}
},
"AuthenticationOptions": {
"AuthenticationProviderKey": "AdminAuthentication",
"AllowedScopes": []
}
} Unless anyone has a better suggestion. Plus I can also think of many other uses for header routing... |
My apologies! I've been buried in other projects in recent months and
haven't had a chance to get back to this issue. But it is still important!
I will try my best to dig back into this very soon. Thanks again!
…On Mon, Sep 23, 2019 at 10:04 AM mrclayman ***@***.***> wrote:
Hi @jrsanbornjr <https://github.com/jrsanbornjr> , I created a pull
request #964 <#964> a few
months ago for the guys to have a look at what I had done. I haven't
received any feedback so I do not know if they had a look at it in the
meantime.
However, I have gotten to the point where I would prefer being able to
route based on claim values so I will likely look into that. Therefore, it
might be preferable if my pull request was not actually merged before I get
this done.
I am also strongly considering adding support for placeholders as per one
of the suggestions above, so that one could specify something like this in
the configuration
"UpstreamRoutingHeaders": {
"Headers": {
"MyHeader": [ "HeaderValue" ]
}
},
"DownstreamPathTemplate" : "https://service/{header:MyHeader}/path"
which seems pretty nifty to me. Similarly, claims might have something
like http://service/{claim:ClaimName}/path. I have not got around to this
yet, though. 🙁
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#360?email_source=notifications&email_token=ABW723OQHNMIOKDTSEYIG53QLDLGTA5CNFSM4FACFRPKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7LFKCA#issuecomment-534140168>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABW723NQ64HNO4TK5XVP5QLQLDLGTANCNFSM4FACFRPA>
.
|
I'm not sure of the implications, but maybe a better option might be a "delegate route strategy" which I think is the idea here #1236 - I'm thinking of the Delegate Strategy as used here In that way your users could use any type of logic to return a delegate value which then can be used in the routing config to determine the route .AddOcelot()
.WithDelegateRouting(ctx => {
//any kind of logic here to return a string
((HttpContext)ctx).Request.Headers.TryGetValue("origin", out StringValues originValue);
return Task.FromResult(originValue.ToString());
}) then in routing config: {
"DelegateRouting": {
"Values": {
"admin.xxx.com",
"another_route"
}
},
} |
I owe you guys an apology, too. 😞 I was the creator of PR #964 back when we (at the company I work for) thought we would make use of that feature. However, we have since made the decision to go a different route that would not require this change and I just have not had the time to finish this so I had to essentially abandon all work done on the task. I have been hoping to return to it asap, but it has not worked out that way yet. |
@PraveenValavan commented on June 29, 2023
Hi Praveen! I recommend going these two ways:
Hope it helps! P.S. Sure, you can wait for final delivery of current feature in a month or two. Now we have a draft solution ( #964 ) from Zbyněk Novotný. |
@mrclayman commented on Jun 29, 2023
No worries! Every company in the world could use Ocelot to build API gateways, including your current one. 😃 Regarding #964 ... It is based on very old, outdated feature branch! Hope you will start development soon! |
@mrclayman We have #1312 by @jlukawska Who will win? ⭐ 😋 |
I bet on her. 😄 I've got the changes I made in the past incorporated into the new state of the code base. I could create a new preliminary PR just so ya'll can see, but I have not tested them (unit tests do pass, though). I would also like to allow the use of placeholders, but I will have to research how to do that first. |
…or the current code base.
Hm, for some reason, many of the changed files are coming up as "rewritten" even though I really only just added the bits I had implemented in the old branch, dammit. Let me know if that is a problem. 😕 Right now I feel like redoing everything. Those diffs are pretty much useless. |
@mrclayman You are unassigned from this ticket because your solution is draft and it is based on very old source code and feature branch which is 247 commits behind ThreeMammals:develop! This issue will be assigned to @jlukawska because of ready and solid PR #1312. The merge conflicts will be resolved soon. |
Well, if you have another solution that is close to being merged, then it makes little sense to me to keep working on this any longer. I am perfectly fine with somebody else picking up the mantle and I don't really want this to become a race. 🙂 |
…or the current code base.
Possible delivery in December... |
* 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]>
* 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]>
Hi,
I'm interested if Ocelot currently supports downstream routing to multiple endpoints based on a Request Header?
A use case for this is something like:
eg.
AU redirects to -> api.internal-au/products
UK redirects to -> api.internal-uk/products
cheers
The text was updated successfully, but these errors were encountered: