caddy icon indicating copy to clipboard operation
caddy copied to clipboard

`lb_policy` for a subset of the path

Open huluxia opened this issue 2 years ago • 6 comments

Why can't add lb_policy hash as custom in caddy

huluxia avatar Jun 25 '23 13:06 huluxia

You're gonna have to be more specific. That's way too vague. Please explain in detail what you mean. Show some examples.

francislavoie avatar Jun 25 '23 14:06 francislavoie

You're gonna have to be more specific. That's way too vague. Please explain in detail what you mean. Show some examples.

Can the lb_policy of reverse_proxy customize hash calculation, for example, can I perform uri_hash calculation based on the specified part of uri instead of the entire uri, such as /path/0 and /path/1, my needs are as long as /path is the same, so whether it is / path/0 and /path/1 next time the same request, go to the backend server allocated last time

huluxia avatar Jun 25 '23 15:06 huluxia

Interesting. That's not currently possible, but we could implement a policy that takes placeholders as input to be replaced. You could pair it with a path_regexp matcher to pull out the bits of the path you need. But if you use a matcher, you have to take care of handling the base case where it doesn't match which can be tricky.

In the short term, I recommend writing a plugin that does what you need. LB policies are pluggable, so you can make it do exactly what you need yourself. See https://caddyserver.com/docs/extending-caddy, existing policy modules are defined here https://github.com/caddyserver/caddy/blob/master/modules/caddyhttp/reverseproxy/selectionpolicies.go

francislavoie avatar Jun 25 '23 15:06 francislavoie

thank you!Hope caddy can add this feature in the future.

huluxia avatar Jun 25 '23 15:06 huluxia

@francislavoie are we still interested in implementing this?

armadi1809 avatar Mar 15 '24 16:03 armadi1809

Sure, we can add it. I'm not sure how it'll look yet so if you make a prototype we can iterate on it 👍 thanks!

francislavoie avatar Mar 15 '24 17:03 francislavoie